Re: SQL Newbie - Join Question
From: jack.lee (lee_j_at_21cn.com)
Date: 11/10/04
- Next message: Derek: "Error message"
- Previous message: Vinod Kumar: "Re: New transaction cannot enlist in the specified transaction coordinator"
- In reply to: Robert: "SQL Newbie - Join Question"
- Next in thread: Robert: "Re: SQL Newbie - Join Question"
- Reply: Robert: "Re: SQL Newbie - Join Question"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 10 Nov 2004 13:49:38 +0800
Hi Robert,
You should use self join like that.
select d.UserID,c1.desc as Desc1, c2.desc as Desc2 from
Data-Table d inner join Code-Table c1
on d.code1 = c1.code inner join Code-Table c2 on d.code2 = c2.code
Thanks!
Jack
"Robert" <Robert@thomasgeorge.com> ????
news:3811e7d4.0411092041.5cee9d71@posting.google.com...
> I have a table with codes in it and I want to return the lookup values
> all in one query....an example is probably easiest:
>
> Code-Table:
>
> code desc
> ---- ----
> 1 desc1
> 2 desc2
> 3 desc3
>
>
> Data-Table:
>
> UserID Code1 Code2
> ------ ----- -----
> ABC 1 2
> DEF 2 3
>
>
> What I want to return is the following:
>
> UserID Desc1 Desc2
> ------ ----- -----
> ABC desc1 desc2
> DEF desc2 desc3
>
>
> I am assuming there is some type of JOIN I should be using, but I
> can't figure out how to get the two differet Desc values from the
> Code-Table in one query. A regular JOIN would get me one of the two
> Desc values, but I need to get two different Desc values by using two
> different WHERE clauses on the same table.
>
> Any solutions would be greatly appreciated!
- Next message: Derek: "Error message"
- Previous message: Vinod Kumar: "Re: New transaction cannot enlist in the specified transaction coordinator"
- In reply to: Robert: "SQL Newbie - Join Question"
- Next in thread: Robert: "Re: SQL Newbie - Join Question"
- Reply: Robert: "Re: SQL Newbie - Join Question"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|