Skip to content
Advertisement

Case when column a from tableX is present in column b of tableY

Below is my use case, i’m querying redshift tables, using case when but get error in case when statement. ERROR: Statement 2 is not valid. ERROR: syntax error at or near “b”

MY SQL query:

What i want to achieve:

DESIRED OUTPUT ( IS ID IN TABLE1 PRESENT IN TABLE2, IF YES THEN 1 ELSE 0 END AS COLUMN_NAME)

Advertisement

Answer

You wouldn’t use “IN” for this even though your desire mentions the word “in”

You’re performing a left join, which will have a value for b.ID where the join succeeded and a null where it failed, hence:

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