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 |
|
nathans
Aged Yak Warrior
938 Posts |
Posted - 2004-12-27 : 18:57:57
|
| Guys,There must be a way to get rid of this subquery...CREATE TABLE #tempMe (temp_id INT, temp_name VARCHAR(10))INSERT INTO #tempMeVALUES(1,'yak') INSERT INTO #tempMeVALUES(1,'foo') INSERT INTO #tempMeVALUES(2,'foo') Now, I want to return all columns for any id that has an occurence temp_name = 'yak'. For example:SELECT * FROM #tempMe WHERE temp_id IN (SELECT temp_id FROM #tempMe WHERE temp_name = 'yak')Can this not be accomplished without a subquery? |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-12-27 : 19:04:02
|
| SELECT t1.temp_id, t2.temp_nameFROM #tempMe t1INNER JOIN #tempMe t2ON t1.temp_id = t2.temp_idWHERE t1.temp_name = 'yak'Tara |
 |
|
|
nathans
Aged Yak Warrior
938 Posts |
Posted - 2004-12-27 : 19:18:57
|
| duh!!! Tara, nice work. Quick too! Thanks :) |
 |
|
|
|
|
|