Multiple tables join in SQL for this scenario

前端 未结 1 1090
北海茫月
北海茫月 2021-01-26 05:15

This is my table structure I have 3 tables:

  1. member table
  2. comments table
  3. comments like table

The tables structures can be found i

相关标签:
1条回答
  • 2021-01-26 05:25

    The following query should work for you. Select required columns from album_comments join it with comment_likes based on comment_id and check if the comment_likes user_id is equal to the user_id you sent from UI. ORDER BY DESC will return latest comments with LIMIT of 20.

    Select |ac.Column1, ac.Column2...ac.Column-n|, cl.like_bit
    FROM album_comments ac INNER JOIN comment_likes cl
    ON ac.id = cl.comment_id AND cl.user_id = |screen user_id|
    ORDER BY ac.id DESC LIMIT 20;
    
    0 讨论(0)
提交回复
热议问题