Redian新闻
>
Late afternoon 腦不好使
avatar
Late afternoon 腦不好使# Database - 数据库
i*a
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?
avatar
i*a
2
Method A:
Query 1
UNION
Query 2
Error: The SELECT INTO statement cannot have same source and destination
tables.
sigh...
avatar
i*a
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)
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。