I have two tables with the same primary key, but one is much much larger than the other. I want to know which ids have a row in the smaller table. (In the example, a
is large and b
is small). Right now, I'm using an OUTER JOIN with a CASE to determine if the b value is NULL or not. It's not working (always getting 1). Fixing this would be fine, but there's got to be a better way. How should I do it?
SELECT a.id,
CASE b.id
WHEN NULL THEN 0
ELSE 1
END AS exists
FROM a LEFT OUTER JOIN b
ON a.id=b.id;