Skip to Main Content

Developer Community

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to join without nulls

brenda_strongJul 1 2024 — edited Jul 2 2024

The main issue I am having is that when I join two tables, the join column may be null in one or both of the join columns. I've been trying to write a query to exclude the nulls, but since they are in the columns to join, nothing seems to work.

The query is like this:

SELECT
a.name_id,
a.name,
a.t_fed_id,
v.std_id_num,
v.vendor_id

FROM name_address a
JOIN vendor v
ON   a.t_fed_id = v.std_id_num

No matter what I've tried, I still get results like this where both columns are null.

Things I've tried,

  • INNER JOIN
  • LEFT JOIN
  • WHERE t_fed_id is null AND std_id_num is null
  • WHERE t_fed_id is null || std_id_num is null
  • CASE WHEN t_fed_id is null then t_fed_id …. etc
  • WHERE EXISTS (SELECT t_fed_id FROM name_address WHERE t_fed_id is not null)
  • WHERE COALESCE(t_fed_id, std_id_num) is not null
  • SELECT …. FROM name_address a, vendor v WHERE t_fed_id = std_id_num AND t_fed_id is not null (instead of JOIN)
  • other variations of the above

Can anyone give me a suggestion that will work please? I can't think of anything else to try.

Thanks

This post has been answered by L. Fernigrini on Jul 3 2024
Jump to Answer
Comments
Post Details
Added on Jul 1 2024
6 comments
909 views