PC Review


Reply
Thread Tools Rate Thread

Left join in query

 
 
Bob Barrows
Guest
Posts: n/a
 
      24th May 2010
I'm glad you've got your answer (actually, I'm a little puzzled about
the answer), but I just needed to throw this in:

> SELECT tblContact.ContactID, tblContact.CaseID, tblContact.Date

You should stop using "Date" as a field name. It's a reserved keyword
(being the name of a VBA function) and its use as a field name will
cause you problems down the road. If it is not too late in the design
process, you should change that fieldname to something more meaningful
(ContactDate?) so as to avoid the reserved keyword issues.

Tara wrote:
> I can't believe it took three people to make me see this! I guess
> I'd just been at it too long because when I came back in this morning
> and read the comments over again, I realized immediately you were all
> right. I guess my brain was just too overworked. It really needed
> the weekend off.
>



--
HTH,
Bob Barrows


 
Reply With Quote
 
 
 
 
Bob Barrows
Guest
Posts: n/a
 
      24th May 2010
John W. Vinson wrote:
> On Thu, 20 May 2010 11:42:01 -0700, Tara
> <(E-Mail Removed)> wrote:
>
>> Here is the query (that doesn't work) that I'm trying to use the
>> above query in:


>> FROM QryAmendedContacts, tblDates
>> WHERE (((QryAmendedContacts.PostedDate) Between
>> [tblDates]![StartDate] And [tblDates]![EndDate]));

>
> As Daryl and Marshall said, you're using a criterion on the query
> field PostedDate. For those records where no query record exists,
> that field will be NULL - and NULL is in fact *not* Between those two
> dates.
>
> Try changing the WHERE clause to
>
> WHERE QryAmendedContacts.PostedDate Between [tblDates]![StartDate] And
> [tblDates]![EndDate] OR QryAmendedContacts.PosteDate IS NULL


I don't understand. PostedDate comes from tblContact, the left side of
the query:

> ..., tblContact.PostedDate, ...
> FROM tblContact LEFT JOIN tblAmendedDates ON tblContact.ContactID =
> tblAmendedDates.ContactID;


If it's not Null in the original table, why would it be Null in the
output of QryAmendedContacts?


--
HTH,
Bob Barrows


 
Reply With Quote
 
 
 
 
Bob Barrows
Guest
Posts: n/a
 
      24th May 2010
John W. Vinson wrote:
> On Thu, 20 May 2010 11:42:01 -0700, Tara
> <(E-Mail Removed)> wrote:
>
>> FROM QryAmendedContacts, tblDates
>> WHERE (((QryAmendedContacts.PostedDate) Between
>> [tblDates]![StartDate] And [tblDates]![EndDate]));

>
> As Daryl and Marshall said, you're using a criterion on the query
> field PostedDate. For those records where no query record exists,
> that field will be NULL - and NULL is in fact *not* Between those two
> dates.
>
> Try changing the WHERE clause to
>
> WHERE QryAmendedContacts.PostedDate Between [tblDates]![StartDate] And
> [tblDates]![EndDate] OR QryAmendedContacts.PosteDate IS NULL


Repro:
tblContact:
ContactID PostedDate
1 5/1/2010
2 5/10/2010
3 5/16/2010
4 5/17/2010
5 5/20/2010
6 5/19/2010


tblAmendedDates:
ContactID AmendedDate AmendmentText
1 5/7/2010 ttt
1 5/8/2010 t2
3 5/20/2010 t1
3 5/21/2010 t2
6 5/20/2010 t1


QryAmendedContacts,
SELECT tblContact.ContactID, tblContact.PostedDate,
tblAmendedDates.AmendedDate, tblAmendedDates.AmendmentText
FROM tblContact LEFT JOIN tblAmendedDates ON tblContact.ContactID =
tblAmendedDates.ContactID;
returns:
ContactID PostedDate AmendedDate AmendmentText
1 5/1/2010 5/7/2010 ttt
1 5/1/2010 5/8/2010 t2
2 5/10/2010
3 5/16/2010 5/20/2010 t1
3 5/16/2010 5/21/2010 t2
4 5/17/2010
5 5/20/2010
6 5/19/2010 5/20/2010 t1

and this query
SELECT QryAmendedContacts.ContactID, QryAmendedContacts.PostedDate,
QryAmendedContacts.AmendedDate, QryAmendedContacts.AmendmentText
FROM QryAmendedContacts
WHERE (((QryAmendedContacts.PostedDate) Between #5/15/2010# And
#5/20/2010#));

returns the expected result:
ContactID PostedDate AmendedDate AmendmentText
3 5/16/2010 5/20/2010 t1
3 5/16/2010 5/21/2010 t2
4 5/17/2010
5 5/20/2010
6 5/19/2010 5/20/2010 t1


What am I missing?


--
Bob Barrows





 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Left Join, Inner Join Nested Query =?Utf-8?B?TGlsTW9yZVBsZWFzZQ==?= Microsoft Access Queries 3 3rd Nov 2006 08:31 PM
Left join is equal to inner join? =?Utf-8?B?R29nemlsbGE=?= Microsoft Access Queries 5 3rd Nov 2006 01:16 AM
Adding another join to Left Join? Noozer Microsoft Access Queries 1 15th Aug 2005 05:55 AM
Left Join acting like inner join??? =?Utf-8?B?VmFjYXRpb24ncyBPdmVy?= Microsoft Access VBA Modules 7 10th Jun 2005 08:35 PM
Left Join with Inner Join not supported? Mark Microsoft Access Queries 2 15th Nov 2003 11:48 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:46 AM.