database - mysql query joining tables to create newsfeed -


i want retrieve rows 3 tables - liketable, closettable, followtable display activities of users person following. website. closettable table user's products. liketable table likes of products , followtable following , followers.

currently, have

select c.user, c.productname closettable c left join followtable f on c.user = f.isfollowed f.follows = 'tony' 

this returns rows of person, 'tony' following productname. however, want rows liketable , followtable in same manner altogether. can suggest way 1 query rows 3 tables?

you can try :

select c.user, c.productname followtable f inner join closettable c on c.user = f.isfollowed inner join liketable l on c.user = l.userliked f.follows = 'tony' 

i assumption fields name since didn't provide structures of tables.

also, suggested put followtable in clause , join closettable since put f.follows = 'tony' in clause.

otherwise, remove clause , put condition in inner join. :

left join followtable f on c.user = f.isfollowed , f.follows = 'tony' 

Comments