php - How to query from two tables with the condition of a third -
i have 3 tables: location user_location image
i need make query takes locationes liked user toggether locations images in third table image.
for managed this:
"select location.* location left join userlocation on location.id = userlocation.location_id userlocation.user_id=:user_id: but retrives locations user liked. need images of every location. how do that?
you need move condition on clause:
select l.*, (ul.user_id not null) hasuser location l left join userlocation ul on l.id = ul.location_id , ul.user_id = :user_id: the where clause filters output in such way turns left join inner join.
Comments
Post a Comment