Home > Mobile >  Please suggest an sql query based on the requirement
Please suggest an sql query based on the requirement

Time:08-24

I have a dynamic sql, where I need to select two columns(say A & B) from the table. I need to generate the result set only if column B has at least one non zero value. If there is no non zero value in the column B, result set should be empty.

CodePudding user response:

Should be that simple, just as you wrote the rule -

select a, b 
from the_table
where exists (select from the_table where b <> 0);
  • Related