sql - MySQL Selecting from multiple rows -
using mysql trying pull people who's company_id matches 3 , compare whether person exists in favourites table.
what have noticed if person has no job_id not output below query.
the below query outputs 1 row, in people table there 3 rows match company_id of 3
select *, j.company_id companyid, f.id not null jid, p.id pid, f.id fave_id, f.id not null fave people p inner join job j on p.job_id = j.id left join favourites f on f.people_id=p.id , f.user_id = 12 p.company_id = 3 order p.id asc any appreciated query output rows match , check favourites table.
if put left join on job, show people have no job_id. have updated fiddle here.
select p.*, j.company_id companyid, f.id not null jid, p.id pid, f.id fave_id, f.id not null fave people p left join job j on j.id = p.job_id left join favourites f on f.people_id=p.id , f.user_id = 12 p.company_id = 3 order p.id asc
Comments
Post a Comment