代码之家  ›  专栏  ›  技术社区  ›  Brian Webster Jason

SQL—在这里执行子查询或扩展WHERE子句更好吗?

  •  1
  • Brian Webster Jason  · 技术社区  · 14 年前

    下面的CUST表将与~10个表连接。

    特别是对于这个子查询,我是否最好直接连接Customer表并将子查询的4部分WHERE子句移动到主查询的WHERE子句?

    select * From 
    (select CKey, CID, CName from MainDB.dbo.Customer 
         where 
            LOC = 'ARK' 
            and Status = 1 
            and CID not like 'KAN%' 
            and CID not like 'MIS%') as CUST
    
    3 回复  |  直到 14 年前
        1
  •  3
  •   OMG Ponies    14 年前

    根据您提供的内容,不需要子查询。没有~10个到派生表的连接 CUST ,很难说应该做什么或者不应该做什么。

        2
  •  5
  •   gbn    14 年前

    但是,为什么不两个都试一下,看看会发生什么呢?

        3
  •  0
  •   DaveWilliamson    14 年前