I have a problem when i'm trying to get posts shares.
First i have a table named : Wa_Posts {id,user_id... etc}
Second table named : Wa_Shares {id,post_id,user_id} .
and for sure Wa_Posts.id = Wa_Shares.post_id
my question is how can get shared posts with all posts ?
My query is:
SELECT
id
FROMWa_Posts
AS post1 WHEREid
>0 ORid
IN (SELECTpost_id
FROMWa_Sares
WHEREuser_id
= USER_ID) ORDER BYid
DESC LIMIT 5
Thank you, and waiting for your help guys !
You can use a LEFT JOIN
to get all shares. Something similar to (untested):
SELECT wa_shares.id share_id, wa_posts.id post_id, wa_posts.user_id user_id FROM wa_shares LEFT JOIN wa_posts ON wa_posts.id = wa_shares.post_id" ORDER BY wa_posts.id DESC LIMIT 5