In Example (a) and Example (b),
I assumed that all T1.tm_id were in T2.
Example (c) would be exactly what you requested.
Quote:
I need to select TM_IDs from table T1 for a particular ALT_ID.
IF TM_ID is zero then I need to select all teams from another table T2. Else TM_ID from table T1.
|
Example (c):
Code:
SELECT COALESCE(t2.tm_id , t1.tm_id) AS tm_id
FROM t1
LEFT OUTER JOIN
t2
ON t1.tm_id = 0
WHERE t1.alt_id = '222'
;