i****a 发帖数: 36252 | 1 SQL 2005
I need to write 2 queries:
Query 1, blah blah blah
Query 2, I need to hit the rows that are NOT in Query 1
Method A:
Query 1, select blah into #temptable where blah = 1
Query 2, select blah not in (select blah from #temptable)
Method B:
Query 1, select blah where blah = 1
Query 2, select bah not in (select blah where blah = 1)
which one is more efficient? Is query optimize gonna make method B more
efficient? Is the only way to know to see query plan? | i****a 发帖数: 36252 | 2 Method A:
Query 1
UNION
Query 2
Error: The SELECT INTO statement cannot have same source and destination
tables.
sigh... | i****a 发帖数: 36252 | 3 seems like CTE works
;with CTE_blah
(
select blah where blah = 1
)
select * from CTE_blah
union
select blah not in (select blah from CTE_blah) |
|