SQL statements to prevent data duplication in multiple table queries in thinkphp (must-see) _php Tips

Source: Internet
Author: User

Let's take a look at the following examples:

Table

ID name
1 a
2 b
3 C
4 C
5 B

The library structure is probably like this, this is just a simple example, the actual situation will be much more complicated.

SELECT *, COUNT (distinct name) from table group by name

Results:

ID Name count (distinct name)
1 a 1
2 B 1
3 C 1

The last one is superfluous, so don't worry about it.

tp2.0 Manual Search consistent operation to see the relevant information

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 a small series for you to bring the thinkphp in multiple tables in the query to prevent data duplication of the SQL statement (must look) of the entire content, I hope to help you, a lot of support cloud Habitat Community ~

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.