Home  >  Article  >  Backend Development  >  A sql query question

A sql query question

WBOY
WBOYOriginal
2016-08-20 08:48:30994browse

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();

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn