Home > other >  Where Equals Subquery Laravel
Where Equals Subquery Laravel

Time:02-01

How can I convert the following SQL query to Laravel:

SELECT *
FROM SomeTable
WHERE some_column = 
(
    SELECT some_column 
    FROM SomeTable st1 
    where st1.some_column2 = SomeTable.some_column2 
)

This query is just an example query. I know that Laravel has a whereIn function for subqueries. I am looking for something similar about equality of a column with a subquery.

CodePudding user response:

DB::table('SomeTable')
->select('*')
->where('some_column','=',function($query) {
    $query->from('SomeTable')
        ->select('some_column')
        ->where('SomeTable.some_column2','=',DB::raw('SomeTable.some_column2'));
})
->get();
  • Related