Say I have two tables:
Users - UserID, UserName
Actions - UserID
The database doesn't have referential integrity, and so If a user has been deleted, the Actions table can still contain the User ID.
I am running a query like:
SELECT DISTINCT UserName FROM USERS u WHERE u.UserId IN (SELECT DISTINCT UserID FROM Actions)
what I want is to be able to adjust the query to say "but, if the user ID doesn't exist in the users table, default to --- instead".
If there was just one value I was searching for, I could do it with a UNION SELECT '---' FROM DUAL WHERE NOT EXISTS (value), but if I try that here they would have to all be missing in order for it to work.
How can I change the query to get the results I want?