Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Collect count from any missing data in rows from MySql

I currently have a counter that will give a total number of entries that is missing information for NAME in the database. I have 3 more fields for this (Name, Address, Phone, Email). I would like the count to show if any of that info is missing, not just the names. (below is what I have so far).

What I have is this

select count(ifnull(name,' ')) AS count FROM `customer` WHERE name IN (' ') != ' '

Another words, if I have for example the following, then the counter would say 3 and also only echo the ones that have the missing fields

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

| id | Name |   Address  |  Phone    |    Email     |
|----|------|------------|-----------| -------------|
| 1  | bob  |  123 main  | 555-5555  |  you@you.com |
| 2  |      |  123 main  | 555-5555  |  you@you.com |
| 3  | ann  |  123 main  |           |  you@you.com |
| 4  | tod  |            | 555-5555  |  you@you.com |

>Solution :

Use COUNT(*) to count the number of rows that meet the WHERE condition.

To count if any of the fields are missing, check them all in the WHERE clause.

SELECT COUNT(*) 
FROM customer
WHERE IFNULL(name, '') = '' or IFNULL(address, '') = '' or IFNULL(phone, '') = '' or IFNULL(email, '') = ''
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading