If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > Unexpected behaviour for left join

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-19-11, 04:48
mmadsen mmadsen is offline
Registered User
 
Join Date: Aug 2011
Posts: 1
Question Unexpected behaviour for left join

I've come across a somewhat unexpected behavior when using custom text in a select and join statement. I use Access 2010. This is a minimal working example

TableA contains:
Id
1
2
3

TableB contains:
Id
1

Code:
SELECT A.Id, S.CustomText FROM TableA AS A
LEFT JOIN (
  SELECT Id, 'My text' as CustomText FROM TableB
) as S ON A.Id = S.Id
Expected result:
Id CustomText
1 My text
2
3

Actual result (bold is unexpected):
Id CustomText
1 My text
2 My text
3 My text

What just happened?? The curious part is that both statements below works just fine..

Code:
SELECT A.Id, S.CustomText FROM TableA AS A
LEFT JOIN (
  SELECT Id, Id as CustomText FROM TableB
) as S ON A.Id = S.Id
Id CustomText
1 1
2
3

Code:
SELECT A.Id, S.CustomText FROM TableA AS A
LEFT JOIN (
  SELECT Id, 'My text' as CustomText FROM TableB UNION
  SELECT Id, 'My text' as CustomText FROM TableB
) as S ON A.Id = S.Id
Id CustomText
1 My text
2
3

Ideas anyone?
Reply With Quote
  #2 (permalink)  
Old 08-19-11, 06:29
Sinndho Sinndho is offline
Registered User
 
Join Date: Mar 2009
Posts: 3,446
Weird but good to know. Thanks for sharing!
__________________
Have a nice day!
Reply With Quote
  #3 (permalink)  
Old 08-19-11, 08:44
weejas weejas is offline
Registered User
 
Join Date: Sep 2006
Location: Surrey, UK
Posts: 448
I'm still stuck on Access 2k, but try adding "WHERE S.ID Is Null" and see what that gives you.
__________________
10% of magic is knowing something that no-one else does. The rest is misdirection.
Reply With Quote
Reply

Tags
custom text, error, left join

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On