Skip to content
Advertisement

Select from column including null values

I’m trying to create SELECT that includes various foreign key to list all the rows it has, but there is two foreign key that can be null.

bank_id and bbank_id can be null, so with this example it only will list rows that doesn’t have null values in bank_id and bbank_id, but I need it to return rows where bank_id and bbank_id are null or not null. I tried using IS NOT NULL AND NULL, well it doesn’t work.

I read something about using LEFT JOIN but no idea how to implement it here.

Advertisement

Answer

You need to use modern JOIN syntax defined in the SQL-92 standard, 27 years ago. Here’s how your query should look using left outer joins:

Welcome to the 21st century! 😉

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement