Skip to content
Advertisement

WHERE returning entire table

Question: How do I ignore WHERE param if value = ‘0’ or NULL

One of the columns returned is showing 0 which is causing problems in my query.

The problem I am having is in the p.author value. Sometimes it matches up with a pe.system_id, but sometimes it is 0 or NULL. If p.author is 0. If I comment the and param out, then it returns a row for each entry in docsadm.people pe1 or nothing because no entry = 0

Advertisement

Answer

There are a number of ways but the way I prefer is to use the JOIN .. ON syntax and make tables with optional data part of a LEFT OUTER JOIN (LEFT JOIN).

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement