For example, in a table, I want to count the number of records with different email and passwords.
Copy codeThe Code is as follows: create table if not exists 'test _ users '(
'Email _ id' int (11) unsigned not null auto_increment,
'Email 'char (100) not null,
'Password' char (64) not null,
Primary key ('email _ id ')
) ENGINE = MyISAM default charset = utf8 AUTO_INCREMENT = 6;
Insert into 'test _ users' ('email _ id', 'email ', 'Password') 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 ',");
We usually do this.Copy codeThe Code is as follows: select count (*) FROM test_users WHERE 1 = 1 group by email, passwords
What is the result?Copy codeThe Code is as follows: COUNT (*)
1
2
1
1
Obviously, this is not the result I want. In this way, the sum of the number of records in the same email and passwords is calculated. The following figure shows the result.Copy codeThe Code is as follows: select count (DISTINCT email, passwords) FROM 'test _ users' WHERE 1 = 1
Of course, you can also use mysql_num_rows in php to obtain the number of records, but this is not efficient. You can refer to this article.
Mysql_num_rows vs count Efficiency Analysis