For example such a table, I would like to count the number of records for which email and passwords are not the same 
 
Copy the Code code as follows:
 
CREATE TABLE IF not EXISTS ' test_users ' (
' email_id ' int (one) unsigned not NULL auto_increment,
' Email ' char (+) not NULL,
' Passwords ' char (+) is not NULL,
PRIMARY KEY (' email_id ')
) Engine=myisam DEFAULT Charset=utf8 auto_increment=6;
 
INSERT into ' test_users ' (' email_id ', ' email ', ' passwords ') VALUES 
(1, ' jims@gmail.com ', ' 1e48c4420b7073bc11916c6c1de226bb '), 
(2, ' jims@yahoo.com.cn ', ' 5294cef9f1bf1858ce9d7fdb62240546′ '), 
(3, ' default@gmail.com ', ' 5294cef9f1bf1858ce9d7fdb62240546′ '), 
(4, ' jims@gmail.com ', "), 
(5, ' jims@gmail.com ', "); 
That's what we're usually doing. 
 
Copy the Code code as follows:
 
SELECT COUNT (*) from test_users WHERE 1 = 1 GROUP by email,passwords
 
What is the result of this? 
 
Copy the Code code as follows:
 
COUNT (*)
1
2
1
1
 
Obviously this is not the result I want, so the statistics are the same email and passwords the number of records of the sum of the following so that it can be 
 
Copy the Code code as follows:
 
SELECT COUNT (DISTINCT email,passwords) from ' test_users ' WHERE 1 = 1
 
Of course, in PHP can also use mysql_num_rows to get the number of records, but this is not high efficiency, you can refer to this article 
Mysql_num_rows VS COUNT Efficiency problem analysis 
The above describes how to use group by when counting the number of records count DISTINCT, including the aspects of the content, I hope the PHP tutorial interested in a friend helpful.