For example such a table, I want to count the number of records with different emails and passwords
Copy 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 () 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 ', ");
Normally, that's what we're doing.
Copy Code code as follows:
SELECT COUNT (*) from test_users WHERE 1 = 1 GROUP by email,passwords
What is the result?
Copy Code code as follows:
Obviously this is not the result I want, so the statistics are the same email and passwords the sum of the number of records, the following is OK
Copy 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 records of the number of bars, but this efficiency is not high, you can refer to this article
Mysql_num_rows VS COUNT Efficiency problem analysis