获取帖子分享MySql和PHP

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 FROM Wa_Posts AS post1 WHERE id >0 OR id IN (SELECT post_id FROM Wa_Sares WHERE user_id = USER_ID) ORDER BY id 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