Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Where Equals Subquery Laravel

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading