Fetch all news and all comments

前端 未结 3 1974
温柔的废话
温柔的废话 2021-01-17 03:33

I\'m trying to code a query that gets all the news and all the comments for each news. My current query is :

SELECT n         


        
3条回答
  •  无人共我
    2021-01-17 04:30

    you can use inner join to get result in a single query.

    Suppose your database structure is like :

    tab_news : news_id, news

    tab_cmt : cmt_id, news_id, cmt

    now write query like:

    select n.news, c.cmt from tab_news n inner join tab_cmt c on (c.news_id=n.news_id)

提交回复
热议问题