SQL Gotchas
20 Nov 2017
-
when comparing columns, always be aware of nulls and how your particular engine treats nulls.
-
when using NVL, use a default value that is not in the possible list of values you are comparing.. so instead of
nvl(valid_ind,'N')
, usenvl(valid_ind,'X')
- assuming x is not a possible value for valid_ind -
always have a driving table and start with that driving table as part of your query, and left join everything else. This will also let you comment out specific parts of the query and see if you are missing rows because of a join. If you have more than one driving table, it might be better to split the query using
with clause
and show how there are two logical different sources at play.