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 

sqlfiddle

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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -