Skip to content
Advertisement

exists query does not return relevant result

I have a Laravel application with this Eloquent query:

This code generates the sql command like:

I am sure there are products which name contains “can” string and which belongs to the category with slug “tonery-cartridge”. Why this query returns an empty result? If I try to make inner join sql manually it works well as on the screenshot below:

phpMyAdmin screenshot

Advertisement

Answer

I think that your queries are not equivalent. The SQL output from laravel does not join tables in it’s FROM clause, but in your manually constructed SQL statement you do a lot of inner joins in your FROM clause and on the resulting table you perform your operations, which is not true for the former.

Try the following

If you want to avoid using whereRaw, you can try the following.

HTH

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement