I'm wanting to select rows from the leftTable that do not have matchings in the rightTable but get the error 'incorrect syntax at WHERE'. It seems like a simple join but I can't get it to work with "WHERE r.id IS NULL".
Am I correct in understanding that a LEFT JOIN / WHERE rightTable.id IS NULL should produce a list of leftTable items that do not have a matching in the rightTable?
SELECT l.*
INTO #temp_length
FROM leftTable l
LEFT JOIN rightTable r
ON l.id = r.id
WHERE r.id IS NULL
AND l.start <= r.start
AND l.end > r.start
WHERE l.type IN ('A', 'B', 'C')
AND l.id IN (SELECT id FROM lookupTable WHERE d_type = 'Z')
AND l.disabled = 'N'
AND r.latest = 'Y';