Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

laravel where in subquery

DB::table('users')
    ->whereIn('id', function($query)
    {
        $query->select(DB::raw(1))
              ->from('orders')
              ->whereRaw('orders.user_id = users.id');
    })
    ->get();

This will produce:

select * from users where id in (
    select 1 from orders where orders.user_id = users.id
)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #laravel #subquery
ADD COMMENT
Topic
Name
9+7 =