Jerum Labsan Jerum Labsan - 7 months ago 10
SQL Question

How to count all records from selected table with empty fields

Assuming I have four tables that I have to select only 3 tables with a Database named Records

Records
1.Cases
2.Ballistics
3.Chem
4.Accounts

Cases
id|year|Natureofcase |
0 | |Repact 1901a |
1 |2003|Repact 1907b |
3 |2004|Repact 1902 |

Ballistics
id|year|Name |Type |
0 |2003| |a-101 |
1 | |Silver-A |a-202 |
3 |2005|Red Cap | |

Chem
id|year|Identified |
0 | |H20+C20 |
1 |2001|Am |
3 |2009| |


SO we have 6 rows with empty tables.
I want to display that sum 6 using PHP. Thank you. Any comments/answers/suggestions will be highly appreciated.

Answer

please try this

SELECT 
   (SELECT COUNT(*) FROM Cases WHERE year = '' OR Natureofcase = '') +
   (SELECT COUNT(*) FROM Ballistics WHERE year ='' OR Name='' OR Type='') +
   (SELECT COUNT(*) FROM Chem WHERE year='' OR Identified='')
AS total_empty