I am using redshift, but I suspect this will be valuable to many other forms of SQL. I am also new to SQL and would appreciate any advice on my query, other than advice which pertains specifically to my question; just please keep it constructive.
QUESTION: How do I avoid returning rows where all rows of my result are NULL?
Here is my query:
SELECT
CASE WHEN events.event_id IN
(SELECT DISTINCT event_id FROM strings_ref WHERE string_id = 123)
THEN event_id END AS 123,
CASE WHEN events.event_id IN
(SELECT DISTINCT event_id FROM strings_ref WHERE string_id = 456)
THEN event_id END AS 456
FROM events
There are many many other string_ids, and this query just returned 1000 consecutive NULLS. EDIT: I have verified that there are results.
NOTE: I have accepted the answer that most pertains to my question, but @gordon-linoff 's answer is more general.