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 |
|
grimmus
Yak Posting Veteran
53 Posts |
Posted - 2011-11-15 : 04:54:02
|
| Hi, I am querying a team statistics table that contains language codes for source and target languages (i.e. eng,esp and so on)I'm doing a join on the languages table so the language description is being outputted instead of the code (i.e. English instead of eng)Currently,I am doing 2 joins on the language table because the team stats table has source and target language columns.Is it possible to avoid using 2 joins for this ?ThanksSELECT T.UserID, src.Description AS SourceLang, tgt.Description AS TargetLang, T.SubjectFROM TeamStats TJOIN Languages src ON src.L_ID = T.SrcLangCodeJOIN Languages tgt ON tgt.L_ID = T.TgtLangCodeWHERE UserID = 2174 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-11-15 : 04:58:04
|
This is the right way - nothing to change. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-15 : 07:26:13
|
Just to show you that there's a way, but not sure whether it would perform better that your original suggestion. So test it and see before you use thisSELECT UserID,Subject,MAX(CASE WHEN LangCode='SrcLangCode' THEN Description ELSE NULL END) AS SourceLang,MAX(CASE WHEN LangCode='TgtLangCode' THEN Description ELSE NULL END) AS TargetLangFROM(SELECT UserID,Subject,LangCode,ValFROM TeamStats tUNPIVOT (Val FOR LangCode IN ([SrcLangCode],[TgtLangCode]))u)mINNER JOIN Languages lanON lan.L_ID = m.ValGROUP BY UserID,Subject ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-11-15 : 07:41:43
|
I want to eat a cake and a potato - is it possible to avoid to use the same mouth?Just to show you that there's a way:You can eat the cake and then open your belly using a knife, put in the potato and then close the wound. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2011-11-15 : 11:20:38
|
quote: Originally posted by webfred I want to eat a cake and a potato - is it possible to avoid to use the same mouth?Just to show you that there's a way:You can eat the cake and then open your belly using a knife, put in the potato and then close the wound. No, you're never too old to Yak'n'Roll if you're too young to die.
Classic :) |
 |
|
|
BruceT
Yak Posting Veteran
78 Posts |
Posted - 2011-11-15 : 13:39:28
|
| How about this one! I want to get to the other side of the road, but I don't want to cross the road? Simple, turn around and walk the other way.....a long long way! :) |
 |
|
|
|
|
|
|
|