|
-
Mar 10th, 2005, 05:33 PM
#1
Frenzied Member
Re: Testing if a record exists in another table
Oh, I get it. I wasn't paying attention!
You'll be needing a subquery then...
VB Code:
strQuery = "SELECT Surname & Chr(44) & Chr(32) & Forenames " & _
"AS FullName, IIF(IsNull(RegMem.MemID), ""N"", ""Y"") " & _
"AS Present From Members LEFT JOIN (SELECT MemID FROM RegMem WHERE SDate = #" & Format(#7/4/2005#, "yyyy-mm-dd") & "#) RegMem " & _
"ON Members.MemID = RegMem.MemID
I doubt if that is syntactically spot on, but you get the idea?
-
Mar 10th, 2005, 05:43 PM
#2
Thread Starter
Lively Member
Re: Testing if a record exists in another table
It works, but I'm not quite clear on the part between the 'LEFT JOIN' and 'ON' - the subquery followed by a table name. How does that work?
-
Mar 10th, 2005, 05:54 PM
#3
Frenzied Member
Re: Testing if a record exists in another table
VB Code:
(SELECT MemID FROM RegMem WHERE SDate = #" & Format(#7/4/2005#, "yyyy-mm-dd") & "#) AS AnyNameYouLike "
The subquery is effectively like an inline query, I just happened to have aliased it to the same name as the table it came from in the previous post (and I was lazy and skipped the 'AS').
You would get the same effect if you created a saved query in access with that SQL, and JOINed on that instead. Does that make it any clearer?
-
Mar 10th, 2005, 06:04 PM
#4
Thread Starter
Lively Member
Re: Testing if a record exists in another table
The missing 'AS' did throw me.
I've now got it as:
VB Code:
strQuery = "SELECT Surname & Chr(44) & Chr(32) & Forenames " & _
"AS FullName, IIF(IsNull(QueryDateOnly.MemID), ""N"", ""Y"") " & _
"AS Present FROM Members LEFT JOIN " & _
"(SELECT MemID FROM RegMem WHERE SDate = #" & _
Format("2005-04-07", "yyyy-mm-dd") & "#) AS QueryDateOnly " & _
"ON Members.MemID = QueryDateOnly.MemID;"
But why is the subquery needed?
-
Mar 10th, 2005, 06:22 PM
#5
-
Mar 10th, 2005, 06:45 PM
#6
Thread Starter
Lively Member
Re: Testing if a record exists in another table
It's an odd concept to get your head around, but I think the first query would be the same as doing:
Code:
"SELECT Surname & Chr(44) & Chr(32) & Forenames " & _
"AS FullName, IIF(IsNull(RegMem.MemID), ""N"", ""Y"") " & _
"AS Present FROM Members, RegMem WHERE SDate = #" & _
Format("2005-04-07", "yyyy-mm-dd") & "# AND " & _
"Members.MemID = RegMem.MemID;"
Thanks for your help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|