mikeee Posted March 11, 2007 Share Posted March 11, 2007 Hi, I did so much research and still cant find the answer to this. I want to count how many fields are left empty in a table. But not all, just specific fields. I have a USERS table, and I just want to count the profile related fields in that table that are left blank. If anyone can help me I would really appreceate it! thanks. I tried to SELECT COUNT from TABLEX where field1='' and field2='' and userid=X No go Link to comment https://forums.phpfreaks.com/topic/42176-need-some-help-with-a-query-please-counting-fields/ Share on other sites More sharing options...
artacus Posted March 11, 2007 Share Posted March 11, 2007 Ok, well if you want to do a count, you probably shouldn't have the "and userid=X" at the end since you'll only have 1 record. This query will help you get a little more detail. I'm assuming you are not allowing nulls. If so, you need to take those into account as well. SELECT COUNT(*) AS num_users, SUM(IF(field1 = '' AND field2 = '', 1, 0)) AS one_and_two, SUM(IF(field1 = '', 1, 0)) AS empty_one, SUM(IF(field2 = '', 1, 0)) AS empty_two FROM users Link to comment https://forums.phpfreaks.com/topic/42176-need-some-help-with-a-query-please-counting-fields/#findComment-204671 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.