Results 1 to 4 of 4
  1. #1
    Atoga is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Mar 2015

    How to join on fields containing nulls

    Hello Everyone,
    I need to join two tables on the SQL Server and the only field they have in common and what I can join on have many null values in each table. I would like to see all the records as a result, so I was thinking of Full Outer Join maybe. What is the best practise/what would you recommend me?

  2. #2
    Ajax is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    you can't join a null field to another field (null or not) so there is no best practice.

    you can display all the records in a table by using something like

    select * from dbotable where somefield is null

    alternative you can try something like (never tested it in a join, so may not work)

    select * from table1 inner join table2 where nz(table1.somefield,1)=nz(table2.somefield,1)

    but if you have 10 records in each table with null values, that will return 100 rows

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Ottawa, Ontario, Canada; West Palm Beach FL

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    I am not an expert with Transact SQL, but I would try with a Left or Right join to start. And then, include some WHERE criteria for the Null situation. Rather than join on fields that have Nulls, can you join on another field that has unique values (Key)? And then use a where clause like ...
    WHERE ((FirstField Is Null AND [SecondField] Is Null)) OR (FirstField >"" AND [SecondField] >"")

    If you want to try a full outer, you will need to create a passthrough query or a View in SQL Server. Perhaps creating more than one JOIN would be beneficial.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Join fields in 2 tables and adding a criteria
    By elenaluiza in forum Access
    Replies: 2
    Last Post: 11-09-2015, 03:25 PM
  2. How to Join Similar Fields Based on a Third Field?
    By Inaccessable in forum Queries
    Replies: 1
    Last Post: 07-12-2013, 03:56 PM
  3. How to join fields?
    By offie in forum Queries
    Replies: 2
    Last Post: 06-20-2013, 03:52 PM
  4. Inner Join and multiple fields
    By mrr2 in forum Queries
    Replies: 25
    Last Post: 05-16-2012, 11:11 AM
  5. join date fields
    By rickscr in forum Database Design
    Replies: 4
    Last Post: 04-22-2011, 10:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Other Forums: Microsoft Office Forums