×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

bad answer for SQL server as well...

It's a typical non-sargable query. This means that the WHERE clause (or at least part of it) of the query cannot take advantage of an index, instead performing a table/index scan, which may cause the query's performance to suffer.

If you currently have a query that uses NOT IN, which offers poor performance because the SQL Server optimizer has to use a nested table scan to perform this activity, instead try to use one of the following options instead, all of which offer better performance:

-Use EXISTS or NOT EXISTS
-Use IN
-Perform a LEFT OUTER JOIN and check for a NULL condition

You can find more in:
Report

Replies, comments and Discussions:

  • 工作学习 / 专业技术讨论 / 关于SQL的小问题, 请DX指教, 看看那个STATEMENT最有效,有个PRODUCT TABLE有PRODNUM栏位, 有个DEPARTMENT表,放PRODUCT属于哪个DEPARTMENT, 现在要找出有那些PRODUCT没有属于DEPARTMENT,不知道哪个SQL STATMENT可以很快的找出来?
    谢谢
    • select * from Product where poductnum not in (select product from Department)
      • This is a good answer for SQL-Server, but not for Oracle, etc.
        • bad answer for SQL server as well...
          It's a typical non-sargable query. This means that the WHERE clause (or at least part of it) of the query cannot take advantage of an index, instead performing a table/index scan, which may cause the query's performance to suffer.

          If you currently have a query that uses NOT IN, which offers poor performance because the SQL Server optimizer has to use a nested table scan to perform this activity, instead try to use one of the following options instead, all of which offer better performance:

          -Use EXISTS or NOT EXISTS
          -Use IN
          -Perform a LEFT OUTER JOIN and check for a NULL condition

          You can find more in:
          • Good point. 但楼主不必介意我和schen的讨论,尽管用open的答案即可。
          • to be honest, i didnot think about perfermance issue at all, i assume the poster only need a answer, he may be a student, (this question is petty like school assignment).
            i just want to give some basic idea.
          • select * from product where not exists ( select * from departemnt where department.product=product.productnum)
            • select DISTINCT * from product where not exists ( select * from departemnt where department.product=product.productnum)