Re: Cannot port OUTER join code from SQL Server to Access 2000
From: Brian (bcap_at_IHATESPAMclara.co.uk)
Date: 02/20/05
- Next message: HB: "Re: number parameterized query, "blank = all"?"
- Previous message: laura: "Re: Pass a parameter to nested query"
- In reply to: ChrisG \(UK\): "Cannot port OUTER join code from SQL Server to Access 2000"
- Next in thread: ChrisG (UK): "Re: Cannot port OUTER join code from SQL Server to Access 2000"
- Reply: ChrisG (UK): "Re: Cannot port OUTER join code from SQL Server to Access 2000"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 20 Feb 2005 09:27:57 -0000
"ChrisG (UK)" <news@nospam.thegrahams.freeserve.co.uk> wrote in message
news:cv5k4q$vnb$1@news6.svr.pol.co.uk...
>
> My first post so be gentle with me :o)
>
> I have an owner table
> Id Name
> 1 Sid
> 2 Bill
> 3 Fred
>
> This links through Owner_id to the Owned table
> Id Owner_id type
> 1 1 1
> 2 2 2
> 3 3 1
> 4 3 2
>
> Sid owns a type 1
> Bill owns a type 2
> Fred owns a type 1 and 2
>
> I want to search for type 1 owners and have them returned plus an
additional
> column that shows if they also own a 2
> Id Name type2
> 1 Sid NULL
> 3 Fred 2
>
> In SQL Server following code works
> SELECT owner.id, owner.name ,o2.type
> FROM owner
> INNER JOIN owned ON owner.id = owned.owner_id
> left outer join owned o2 on owner.id=o2.owner_id and o2.type=2
> Where owned.type=1
>
> Access initially gives me this
> SELECT owner.id, owner.name
> FROM owner
> INNER JOIN owned ON owner.id = owned.owner_id
> WHERE (((owned.type)=1));
>
> Then I add
> left outer join on owned as o2 where o2.owner_id = owner.id and o2.type=2
> And it complains.
>
> Any help gratefully received.
>
> Chris....
>
>
Unfortunately Access is much less smart than SQL Server at figuring out join
expressions. Access insists on having parentheses to help it understand.
This will probably do it for you:
SELECT owner.id, owner.name ,o2.type
FROM (owner
INNER JOIN owned ON owner.id = owned.owner_id)
left join owned o2 on owner.id=o2.owner_id and o2.type=2
Where owned.type=1
- Next message: HB: "Re: number parameterized query, "blank = all"?"
- Previous message: laura: "Re: Pass a parameter to nested query"
- In reply to: ChrisG \(UK\): "Cannot port OUTER join code from SQL Server to Access 2000"
- Next in thread: ChrisG (UK): "Re: Cannot port OUTER join code from SQL Server to Access 2000"
- Reply: ChrisG (UK): "Re: Cannot port OUTER join code from SQL Server to Access 2000"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|