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 |
|
davidshq
Posting Yak Master
119 Posts |
Posted - 2005-06-15 : 10:28:35
|
| Games Table:CREATE games (id, title, description, type)INSERT INTO games (title, description, type) VALUES (Dodgeball, a game, 1)INSERT INTO games (title, description, type) VALUES (Bopper, a game, 4)CREATE gametypes (id, type)INSERT INTO gametype (type) VALUES (active inside)INSERT INTO gametype (type) VALUES (chair game)==So, I have two tables. There are actually ten types of games, but two samples should do. I want to perform a join (I think, unless there is an easier way) that joins the tables where the games.type=gametype.id but have it display not the gametype.id but the gametype.type.So I tried something like:SELECT * FROM games G LEFT JOIN gametypes GT ON G.Type=GT.IDBut the result set as may be excepted gives back the following:Dodgeball, a game, 1Whereas what I want is:Dodgeball, a game, active insideAny ideas? Thanks.David.- http://www.civilwarsearch.com/- http://www.thehungersite.com/- http://www.grid.org/ |
|
|
mr_mist
Grunnio
1870 Posts |
Posted - 2005-06-15 : 10:44:33
|
| Think about what you are asking for a little moreSELECT * FROM games G LEFT JOIN gametypes GT ON G.Type=GT.IDis not going to get what you are asking for so..SELECT g.title, g.description, gt.type FROM games G LEFT JOIN gametypes GT ON G.Type=GT.ID-------Moo. :) |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-06-15 : 10:46:37
|
| SELECT G.title,G.description, GT.type FROM games G LEFT JOIN gametypes GT ON G.Type=GT.IDMadhivananFailing to plan is Planning to fail |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2005-06-15 : 10:56:14
|
Not sure if this is what you want....but it was a good shot at a nice post...Try it like this though...USE NorthwindGOSET NOCOUNT ONCREATE TABLE games ([id] int, title varchar(50), [description] varchar(255), type int)CREATE TABLE gametypes (type int, typeDesc varchar(50))GOINSERT INTO games (title, [description], type)SELECT 'Dodgeball', 'a game', 1 UNION ALLSELECT 'Bopper', 'a game', 4INSERT INTO gametypes (type, typedesc) SELECT 1, 'active inside' UNION ALLSELECT 4, 'chair game'GOSELECT * FROM games g JOIN gametypes t ON g.type = t.typeGOSET NOCOUNT OFFDROP TABLE gamesDROP TABLE gameTypesGO Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx |
 |
|
|
|
|
|
|
|