1

I have a large table with alot of column and I want to check if any column is empty

The way that i aproach this is by writing the query and check very column one by one, but it is not a good practice for tables that have more than 20 columns, the query will be to long and tiring to write

Select * from Table_name where `col1` = '' or `col2` = '' or `col3` = '' or `col3` = '' or `col4` = '' or `col5` = '' or `col6` = '' or `col7` = '' or ....... `col20` = '' 

Is there any "Loop like" query to loop over all columns names without writing them in the query and check them one by one?

Edit For people marked my question as duplicated:

My question asking to check all column at once if they are Null or empty not only one column

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
Nasser Hajlawi
  • 313
  • 2
  • 15
  • 2
    Relational databases aren't supposed to be defined this way so there's no accommodations to make this easier. You can expand this in code, though, using an array of columns to check. That helps minimize how much code you write as well as potential typographical errors. – tadman Jul 23 '19 at 23:58
  • Possible duplicate of [How do I check if a column is empty or null in mysql](https://stackoverflow.com/questions/8470813/how-do-i-check-if-a-column-is-empty-or-null-in-mysql) – Mustafa Salih ASLIM Jul 24 '19 at 00:02
  • 1
    @MustafaSalihAslım I don't think it's a duplicate, that question is how to check on a single field if it's empty OR null, this question is how to check on multiple fields if they are empty in a short way – Moses Schwartz Jul 24 '19 at 00:22
  • Note that this kind of problem can be symptomatic of poor (inadequately normalised) design. – Strawberry Jul 24 '19 at 04:48

1 Answers1

4

You can use WHERE IN()

SELECT * FROM Table_name WHERE "" IN (col1,col2,col3...)

Moses Schwartz
  • 2,857
  • 1
  • 20
  • 32