mysql - how to get values from 2 tables based on common table -


//table 1 (favourite)

id || user_id || event_id || news_id 1        1          1           0 2        1          0           1 

//table 2 (event)

event_id || name || location || descr    1        jit       ekm       demo  

//table 3 (news)

 news_id || title || news || location     1       demo      no       thr 

my question table 1, when news_id field 0 display values table 2 according event_id values in table 1 , when event_id field 0 display values table 3 according news_id values in table 1.

is possible. how make this.

this should trick you-- it's joining tables based on values present in favourite table:

select    f.id, f.user_id,           e.event_id, e.name event_name, e.location event_location, e.descr event_descr,           n.news_id, n.title news_title, n.news, n.location news_location      favourite f left join event e on e.event_id = f.event_id left join news  n on n.news_id  = f.news_id 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -