For example, in a table like this, I want to count the number of records with different emails and passwords
Copy code The 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,
`passwords` char(64) 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', ”);
Usually this is how we do it
Copy code The code is as follows:
SELECT COUNT(*) FROM test_users WHERE 1 = 1 GROUP BY email,passwords
What is the result of this?
Copy code The code is as follows:
COUNT(*)
1
2
1
1
Obviously this is not the result I want. What is counted is the sum of the number of records with the same email and passwords. The following is enough
Copy code The code is as follows:
SELECT COUNT(DISTINCT email,passwords) FROM `test_users` WHERE 1 = 1
Of course in php You can also use mysql_num_rows to get the number of records, but this is not efficient. You can refer to this article
mysql_num_rows VS COUNT efficiency problem analysis
http://www.bkjia.com/PHPjc/323248.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323248.htmlTechArticleFor example, in a table like this, I want to count the number of records with different emails and passwords. Copy the code as follows: CREATE TABLE IF NOT EXISTS `test_users` ( `email_id` int(11) unsigned...