Join with null values (1 Viewer)

Tskutnik

Registered User.
Local time
Today, 12:31
Joined
Sep 15, 2012
Messages
229
Hey all,

My query has multi-field joins between 2 tables. Is it possible to include Null values on both sides of the joined tables as equal values in one of the joins, so the records relate?

In this case the first join is on actual values (the normal way), but the second could have null on both sides, which I'd want to relate as equal.

Thanks
 

boerbende

Ben
Local time
Today, 18:31
Joined
Feb 10, 2013
Messages
339
I think you'll have to look into "left join" or "right join" queries
 

isladogs

MVP / VIP
Local time
Today, 17:31
Joined
Jan 14, 2017
Messages
18,209
Hey all,

My query has multi-field joins between 2 tables. Is it possible to include Null values on both sides of the joined tables as equal values in one of the joins, so the records relate?

In this case the first join is on actual values (the normal way), but the second could have null on both sides, which I'd want to relate as equal.

Thanks

As already described by Ben, use outer joins.
However you need to be aware that Null doesn't equal anything - not even another null

Try typing this in the VBE immediate window
?1=1
The result is true (obviously)

?2=1 gives False

?Null=Null
The result is Null
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 12:31
Joined
Feb 19, 2002
Messages
43,225
This is indicative of a design flaw. The multi-fields should probably be in separate tables since they are optional.

However, if you are not prepared to redesign, you might be able to solve the problem by changing the datatype of the optional fields to text. You also have to make the default ZLS rather than null and when you append data, convert any null values to ZLS.

As has already been mentioned, Null is nothing and Null = Null returns null. Since, ZLS is something that means ZLS will = ZLS allowing you to join the two fields.
 

Mark_

Longboard on the internet
Local time
Today, 09:31
Joined
Sep 12, 2017
Messages
2,111
@Pat,

I take it ZLS = "Zero Length String", or ""?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 12:31
Joined
Feb 19, 2002
Messages
43,225
Yes. ZLS = Zero Length String. It is coded as --- """ ---- two double quotes with nothing between them and is different from Null.
 

isladogs

MVP / VIP
Local time
Today, 17:31
Joined
Jan 14, 2017
Messages
18,209
Yes. ZLS = Zero Length String. It is coded as --- """ ---- two double quotes with nothing between them and is different from Null.

Methinks you were a little too keen typing double quotes as I can see three!
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 12:31
Joined
Feb 19, 2002
Messages
43,225
Thanks Colin. Apparently I have developed a stutter.
 

Mark_

Longboard on the internet
Local time
Today, 09:31
Joined
Sep 12, 2017
Messages
2,111
Just trying to cut down on the unexplained MLAs floating around here. I wrote a paper on proper use of MLAs a while back.

B-) Just so anyone who's really interested knows, MLA = Multi Letter Acronym.
 

Mark_

Longboard on the internet
Local time
Today, 09:31
Joined
Sep 12, 2017
Messages
2,111
@Colin,

Rather than risk having anyone bother the Officer in Charge, I thought it prudent to explain his meaning...
 

isladogs

MVP / VIP
Local time
Today, 17:31
Joined
Jan 14, 2017
Messages
18,209
At the time, I wondered if he was calling me an oick....!:)
 

CJ_London

Super Moderator
Staff member
Local time
Today, 17:31
Joined
Feb 19, 2013
Messages
16,607
From Colins link I see ZLS also stands for Zero Lifetime Space - now does anyone want to explain what that is?
 

isladogs

MVP / VIP
Local time
Today, 17:31
Joined
Jan 14, 2017
Messages
18,209
It means spending so long on forums answering questions that you don't have time to develop your own applications....;)
 

Mark_

Longboard on the internet
Local time
Today, 09:31
Joined
Sep 12, 2017
Messages
2,111
Or have one of these so called "Lives"?
 

Users who are viewing this thread

Top Bottom