Home >Backend Development >PHP Tutorial >A sql query question
I want to sort by the number of comments on the article and query the articles with the top 5 comments. There are two tables, the article table and the
comments table. I used inner joins before, and all the public parts were obtained, so I filtered them out. The result must have the number of comments. If the number of comments is 0, nothing can be found. What I want is not such a result. My requirement is to be able to participate in the sorting even if the number of comments is 0. I checked online and it should be I am using full connection, but it is reporting an error. I also did a test and it seems that all full connections will report an error. The following code uses thinkphp. $hotArticle = $articleModel->join('sys_comment on sys_comment.article_id=sys_article.article_id ','FULL')->field('sys_article.
,count(
) as num')->group('sys_article.article_id')->order('count(*) desc')-> ;limit(5)->select();