An SQL query problem

Source: Internet
Author: User
I want to sort and query the top five comments by the number of comments in the article. There are two tables, the article table and the comment table. I used internal connections, the results are all public parts, so the filtered results must contain comments. if the number of comments is 0, nothing can be found. what I want is not... I want to sort the number of comments in the article and query the first five comments. There are two tables, the article table and
In the comment table, we used an inner join to obtain all the public parts. Therefore, the filtered result must have a comment volume. if the comment volume is 0, I don't want such a result. my requirement is that even if the number of comments is 0, I can participate in the sorting. I checked it online and should use the full connection, however, an error is reported and a test is conducted. it seems that all 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 ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.