mysql - SQL - Combine a select * query with select 1 -
i'm trying combine data 2 tables in 1 result. simplified example-tables, want in result:
id text choice -------------------------------- 1 first choice 0 2 second choice 0 3 third choice 1
from 2 tables persons , choosen
'persons':
id name age ------------------- 1 adam 22 2 scott 25 3 tom 28
'choices':
id text ---------------------- 1 first choice 2 second choice 3 third choice
'choices_made':
person_id choice_id ---------------------- 2 3
i have tried different queries, not found right one. got stuck when trying query:
select * ( (select * choices) t1 union (select 1 choice choices_made person_id=2) t2 ) t_union
... not work. causes error #1064 - have error in sql syntax.
any suggestions on how can accomplish wanted result?
you can try next query
select choices.* ,if(choices_made.choice_id null, 0, 1) choice choices left join choices_made on choices_made.choice_id = choices.id , choices_made.person_id = @personid
Comments
Post a Comment