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 |
|
Jacmac
Starting Member
11 Posts |
Posted - 2005-06-24 : 12:53:34
|
| I need a select statement that will return rows from table one depending on a column (type) in table two. For example:Table 1ID-----|DescC0001-|ChamberC0002-|Walk-inC0003-|Refrigeration...Table 2ID-----|TypeC0001-|SC0002-|SC0003-|G...The query needs to return ID's in Table 1 that exist in Table 2 with Type S or G.Sorry if this is a overly simple question, I don't spend too much time on SQL. Thanks, Jacmac |
|
|
Kristen
Test
22859 Posts |
Posted - 2005-06-24 : 14:18:49
|
Something like this?SELECT T1.ID, T1.DescFROM Table1 T1 JOIN Table2 T2 ON T2.ID = T1.IDWHERE T2.Type IN ('S', 'G')Kristen |
 |
|
|
Jacmac
Starting Member
11 Posts |
Posted - 2005-06-24 : 15:21:29
|
quote: Originally posted by Kristen Something like this?SELECT T1.ID, T1.DescFROM Table1 T1 JOIN Table2 T2 ON T2.ID = T1.IDWHERE T2.Type IN ('S', 'G')Kristen
Thanks Kristen, I'm not very good at this, but the final statements that work are:select * from Active_Chambers T1 join Chamber_Table T2 on T2.INS_Number = T1.INS_Number where T2.Chamber_Type='S'and select * from Active_Chambers T1 join Chamber_Table T2 on T2.INS_Number = T1.INS_Number where T2.Chamber_Type='G' |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-06-24 : 15:27:40
|
| Jacmac,Don't use two queries when you can do it in one. Kristen's solution pulls your two together. IN is just a shorter way of saying OR.Tara |
 |
|
|
Jacmac
Starting Member
11 Posts |
Posted - 2005-06-24 : 17:44:07
|
quote: Originally posted by tduggan Jacmac,Don't use two queries when you can do it in one. Kristen's solution pulls your two together. IN is just a shorter way of saying OR.Tara
Thanks, but I actually needed to do seperate queries to fill two different temporary tables in my program. |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2005-06-24 : 23:50:32
|
If you are new to it then I'd recommend you don't use SELECT * (unless that was just for your post here). You should always (even if you think its a Pain!) put the list of columns you want.(If you didn't already know that by all means ask "Why?" )Kristen |
 |
|
|
|
|
|