In SQL, How we make a check to filter all row which contain a column data is null or empty ?
For examile
Select Name,Age from MEMBERS
We need a check Name should not equal to null or empty.
Use the IS NULL operator in a condition with WHERE to find records with NULL in a column. Of course, you can also use any expression instead of a name of a column and check if it returns NULL. Nothing more than the name of a column and the IS NULL operator is needed (in our example, middle_name IS NULL ).
You can use the WHERE clause to filter unwanted rows from the result. This filtering capability gives the SELECT statement its real power. In a WHERE clause, you specify a search condition that has one or more conditions that need to be satisfied by the rows of a table.
This will work in all sane databases (wink, wink) and will return the rows for which name is not null nor empty
select name,age from members where name is not null and name <> ''
For DBMSs that treat '' as a value (not null), Vinko's query works:
select name,age from members where name is not null and name <> ''
For Oracle, which treats '' as a null, tha above doesn't work but this does:
select name,age from members where name is not null
I tried to think of a "DBMS-agnostic" solution, but failed - mainly due to the different concatenation operators/functions used by different DBMSs!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With