sqlwhere-clause

WHERE clause pulling incorrect values


I am calling a table and looking to find null values. Where report_date is looking for TRUE and two other columns are looking for FALSE, I seem to be getting inflated numbers and I believe it is the order of operations after my WHERE clause.

SELECT DISTINCT
    "report_date",
    "department",
    "business_unit"
FROM
    "system"
WHERE 
    "report_date" IS TRUE
    AND "department" IS FALSE
    OR "business_unit" IS FALSE;

I was expecting just to see the null values listed where the conditions are met, but it seems now the report date is pulling FALSE values.


Solution

  • as mentioned in a comment, dont "quote" column names, but also may be getting incorrect values due to the where clause having the OR. Probably try something more like

    SELECT DISTINCT
          report_date,
          department,
          business_unit
       FROM
          system
       WHERE 
           report_date IS TRUE
        AND ( department IS FALSE
           OR business_unit IS FALSE )
    

    Notice (parenthesis) around the OR testing on department and business unit.