Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

My query needs to return all 20 columns for each row that does not contain a NULL in any of those columns. The query I have is:

Select Col1, Col2, ... Col20
from table 
where Col1 is not null 
and Col2 is not null 
and ...
and Col20 is not null..

Is this the best or only approach?

share|improve this question
    
Are you trying to display only those rows in which every single column has data? If so then yes, this is the way to do it. Horizontal scaling is not a strong point of relational databases. –  Andrew Brennan Mar 14 at 11:25
    
I think this would be much better and easier. You should also have appropriate indexes to speed up the query execution. You would have to validate the query anyway. –  Goni Mar 14 at 11:25
1  
Well, if you have not null constraints on any of these columns then you don't need to check those... –  Colin 't Hart Apr 14 at 19:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.