I’m a beginner at SQL and have this fairly easy conditional problem: Every installation number in the database has a customer. But I have been told that the customer is in either the AUDEB table or the AFORD table. I should first look in AUDEB for CUSTOMER_NO and use that if it is not NULL. If it is NULL, then take the CUSTOMER_NO from the AFORD table.
Use this if CUSTOMER_NO is not NULL
SELECT CUSTOMER_NO
FROM AUDEB
WHERE INST_NO = 2
Else use this CUSTOMER_NO
SELECT CUSTOMER_NO
FROM AFORD
WHERE INST_NO = 2
I see that there exist IF…ELSE condtions in SQL, but isn’t there an easier way of selecting between the values from two queries where I want to use the first if the result is not null, else use the other?
You could
unionthe tables using a subquery to retrieve a complete list of customers: