mysql - Sql left join across two columns with filter -


update: resolved, making syntax error.


can join , filter across 2 columns in left join? example:

tbl_people id    food     side     value     pizza    fries    10 b     pizza    shake     2 c     burger   fries    3  tbl_sides food     side pizza    fries burger   fries 

then using sql:

select    id, food, side, value   tbl_people people left join   tbl_sides sides on sides.food = people.food   , sides.side = people.side 

can add flag can determine whether or not food pair in joined or if it's null? don't want inner join, because need count total food/sides per person, , matching food/side pairs per person. tried:

select    id, food, side, value,   case when     side.side not null     , side.food not null     1     else 0   end match_flag   tbl_people people left join   tbl_sides sides on sides.food = people.food   , sides.side = people.side 

but it's not working. need flag when join isn't applied i'm having trouble.

i think want this:

select    id, food, side, value,   case when     side.side = people.side      1     else 0   end match_flag   tbl_people people left join   tbl_sides sides on people.food = sides.food 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -