Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Shiva808
Starting Member
6 Posts |
Posted - 2007-04-25 : 19:20:01
|
Hi, I cant for the life of me work this out. I have a table of keys like:LINEUP======Vocals Guitar Bass Drums------ ------ ---- -----1 2 3 45 2 6 5 With the key values in the Member table like:MEMBER======ID Name-- ----1 Joe2 Greg3 Paul4 Mick5 Dave6 Bill Now I need to return the lineup table but with the names not keys likeRETURNED RESULT===============Vocals Guitar Bass Drums------ ------ ---- -----Joe Greg Paul MickDave Greg Bill Dave Please how can I do this?Thanks |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-04-25 : 19:26:12
|
[code]select v.Name as Vocals, g.Name as Guitar, b.Name as Bass, d.Name as Drumsfrom LINEUP l inner join MEMBER v on l.Vocals = v.ID inner join MEMBER g on l.Guitar = g.ID inner join MEMBER b on l.Bass = b.ID inner join MEMBER d on l.Drums = d.ID[/code] KH |
 |
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2007-04-25 : 19:28:57
|
[code]Declare @keys table ( Vocals int, Guitar int, Bass int, Drums int)insert into @keys select 1 ,2 ,3, 4 union allselect 5 ,2 ,6 ,5select * from @keysdeclare @MEMBER table (id int, name varchar(50) )insert into @MEMBER select 1 ,'Joe' union allselect 2 ,'Greg' union allselect 3 ,'Paul' union allselect 4 ,'Mick' union allselect 5 ,'Dave' union allselect 6 ,'Bill'--select * from @MEMBERselect m.*, m2.* , m3.*, m4.*from @keys kjoin @MEMBER M on k.Vocals = m.idjoin @MEMBER M2 on m2.id = k.Guitar join @MEMBER m3 on m3.id = k.Bassjoin @MEMBER m4 on m4.id = k.Drums[/code]************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
 |
|
Shiva808
Starting Member
6 Posts |
Posted - 2007-04-25 : 19:42:05
|
Awsome guys, thanks very much for your help |
 |
|
|
|
|
|
|