SQL statements that prevent repeated data in Multi-table queries in thinkphp (mandatory) and thinkphpsql

Source: Internet
Author: User

SQL statements that prevent repeated data in Multi-table queries in thinkphp (mandatory) and thinkphpsql

Let's take a look at the example below:

Tableid name1 a2 b3 c4 c5 B

The library structure is like this. This is just a simple example, and the actual situation is much more complicated.

Select *, count (distinct name) from table group by name

Result:

Id name count (distinct name) 1 a 12 B 13 c 1

The last item is redundant.

You can see the relevant information for consistent operations in tp2.0 manual search.

SELECT cat_id, COUNT (*) AS goods_num FROM talble group by cat_id $ M = M ('table '); $ rs = $ M-> field (array ('cat _ id', 'count (*) '=> 'goods _ num ')) -> group ('cat _ id')-> select (); echo $ M-> getLastSQL (); print_r ($ rs );

The above is all the content of the SQL statement (mandatory) that prevents data duplication in Multi-table queries in thinkphp provided by xiaobian. I hope it will help you and support more help ~

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.