BruceyBandit BruceyBandit - 1 month ago 8
SQL Question

PostgresQL, only contain not null values

I'm trying to output a query where if any of the following columns contains NULL value (or for current sheet does not contain an empty string), then output the results, but it is still outputting results with null values. What am I doing incorrectly?

select *
FROM public._http_requests
WHERE ((_http_requests.currentsheet IS NOT NULL OR _http_requests.currentsheet != '')
OR _http_requests.session_id IS NOT NULL
OR _http_requests.http_referer IS NOT NULL)

Answer

Replace OR with AND to make sure all columns in where clause does not have any NULL value

SELECT *
FROM   PUBLIC._http_requests
WHERE  (_http_requests.currentsheet IS NOT NULL OR _http_requests.currentsheet != '')
       AND _http_requests.session_id IS NOT NULL
       AND _http_requests.http_referer IS NOT NULL 
Comments