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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.