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 ~