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 |
|
thomas49th
Starting Member
1 Post |
Posted - 2010-08-05 : 15:52:29
|
| Hi, I have three tablestable_1, table_2, table_3table_1 has field ID, CID, NameThere can be CID to Name is many to manytable_2 has fieldsID, CID, Typelikewise CID to Type is many to manytable_3 has fieldsType, SolutionThe last table is one to one. So one type has one solutionNow what I want to do is input a name and get out all the solutionsSo say I input TomIn table_1 we have the data:CID, Name1, Tom1, Pete2, TomSo I grab the CIDs from Tom which are 1,2 and stick that In table_2:CID, Type 1, X1, Z2, Y(I ignored ID as that's there for primary key)So putting type into table_3:Type, SolutionX, NothingY, ReturnZ, JumpSo output would be Nothing, ReturnHow do I make that into a query form thoughI tried:"SELECT table_3.SolutionFROM table_1, table_2, table_3WHERE table_1.name='$name' AND table_2.CID = table_1.CIDAND table_3.Type = table_2.Type"but that doesn't workAny ideas?ThanksThomas |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2010-08-05 : 15:57:22
|
| [code]SELECT SolutionFROM table_1 t1JOIN table_2 t2On t1.CID = t1.CIDJOIN table_3 t3On t3.Type = t2.TypeWHERE t1.Name = 'Tom'[/code] |
 |
|
|
|
|
|
|
|