Re: Left Join woes
From: Michel Walsh (vanderghast_at_VirusAreFunnierThanSpam)
Date: 08/18/04
- Next message: Franky: "LARGE function in access 2000"
- Previous message: Michel Walsh: "Re: two date fields criteria"
- In reply to: anonymous_at_discussions.microsoft.com: "Left Join woes"
- Next in thread: Nathan: "Re: Left Join woes"
- Reply: Nathan: "Re: Left Join woes"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 18 Aug 2004 06:47:17 -0400
Hi,
That join is ambiguous, meaning if you execute the inner join first, then
the left join, you get a different result than if you do the left join
first, then the inner join. It would NOT be an ambiguous join if the inner
join would NOT involved the unpreserved side of the left join... but the ON
condition of the inner join actually implies the right table of the left
join... so it is an ambiguous join.
Theory aside, with Jet, you cannot use the parenthesis to indicate the order
of execution. Basically, you make two queries, the first one make the first
join you want, the second query use the first query, as table, and execute
the last join. You can do it in one query, using virtual table.
If you meant the inner join, then the outer join:
SELECT i.*, x.*
FROM issues As i LEFT JOIN
( SELECT n.*, in.issueKey
FROM issue_Note AS in
INNER JOIN note AS n
ON in.NoteKey=n.NoteKey)
As x
ON i.IssueKey=x.IssueKey
If you meant the reverse, you probably can do better with just inner join,
since the first left join would make some in.NoteKey values NULL (if not,
then again an inner join is enough) and the last join, an inner join on
those NULL would disregard them anyhow. So:
SELECT i.*, n.*
FROM ( Issue AS i INNER JOIN Issue_Note AS in
ON i.IssueKey=in.IssueKey
) INNER JOIN Note AS n
ON in.NoteKey=n.NoteKey
should do. Jet (seems to) require the parenthesis to "group" the ON with the
JOIN it is to be applied, explicitly (even if it can live without, in some
cases, but I never studied the patterns).
Hoping it may help,
Vanderghast, Access MVP
<anonymous@discussions.microsoft.com> wrote in message
news:828701c484fc$84141470$a401280a@phx.gbl...
> Extract from db that I am trying to construct query on:
>
> Tables:
>
> Issue
> Issue_Note
> Note
>
> Relationships:
> Issue one-to-many Issue_Note - joined on IssueKey
> Issue_Note one-to-many Note - joined on NoteKey
>
> As you can see the the Issue_Note table is basically a
> link table holding details of the notes for a specific
> issue.
>
> I have written the sql I am trying to create in T-SQL
> syntax below as I appear unable to create it within access
>
> SELECT i.*, n.*
> FROM Issue AS i
> LEFT JOIN Issue_Note AS in ON i.IssueKey=in.IssueKey
> INNER JOIN Note AS n ON in.NoteKey=n.NoteKey
>
> Can anybody help me get a working access query to do this.
>
> Nathan
- Next message: Franky: "LARGE function in access 2000"
- Previous message: Michel Walsh: "Re: two date fields criteria"
- In reply to: anonymous_at_discussions.microsoft.com: "Left Join woes"
- Next in thread: Nathan: "Re: Left Join woes"
- Reply: Nathan: "Re: Left Join woes"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|