mysql - Create a virtual column to verify if data exists on anothers -
mt_user:
usr_id usr_login usr_passwd 1 user1 user1 2 user2 user2 3 user3 user3 4 user4 user4
mt_settings:
sttgs_id sttgs_description 1 setting 1 2 setting 2 3 setting 3 4 setting 4 5 setting 5
mt_user_settings:
uss_id usr_id sttgs_id 1 1 1 2 1 2 3 2 5 4 3 2 5 3 3 6 3 5 7 4 4
what need show data this:
where usr_id='2'
:
sttgs_id sttgs_description has it? (virtual_column) 1 setting 1 0 2 setting 2 0 3 setting 3 0 4 setting 4 0 5 setting 5 1
where usr_id='3'
:
sttgs_id sttgs_description has it? (virtual_column) 1 setting 1 0 2 setting 2 1 3 setting 3 1 4 setting 4 0 5 setting 5 1
how correctly?
select s.sttgs_id, s.sttgs_description, if(st.uss_id,1,0) `has it` mt_user u join mt_settings s left join mt_user_settings on us.usr_id = u.usr_id , us.sttgs_id = s.sttgs_id u.usr_id = 2
you can without users table
select s.sttgs_id, s.sttgs_description, if(st.uss_id,1,0) `has it` mt_settings s left join mt_user_settings on us.usr_id = 2 , us.sttgs_id = s.sttgs_id
Comments
Post a Comment