删除SELECT语句未选中的所有行

时间:2013-11-15 15:39:16

标签: sql sql-server-2008 select sql-delete

我有一张表,列出了耗材及其库存部门...单个供应可以有多个库存部门,因此它们将是多行,具有相同的供应但不同的部门(有些具有多个其他不具备)我有一个脚本选择我不想删除的所有耗材。

SELECT supply_num, 
       Min(tisclient_num)               AS tisclient_num, 
       Min(invdept_num)                 AS invdept_num, 
       Min(usage_freq)                  AS usage_freq, 
       Min(qty_on_hand)                 AS qty_on_hand, 
       Min(min_level)                   AS min, 
       Min(max_level)                   AS max, 
       Min(primary_supply_location_num) AS location, 
       Min(par_level)                   AS par 
FROM   mm_supply_tisclient_invdept 
GROUP  BY supply_num; 

如何从此表中删除未在此select语句中选择的所有内容?

1 个答案:

答案 0 :(得分:1)

您是否尝试过delete from TABLE_NAME where FIELD not in (select ... )