简体   繁体   中英

Delete based on a group in SQL Server

I want to delete records with the same combination of records from a table using this query. The syntax works in PostgreSQL but not in SQL Server. What could be the reason?

    DELETE FROM  Table_stg
         WHERE (cid , t_date , i_location , item ) in
             (SELECT b.cid , b.t_date, b.i_location, b.itemFROM  Table_vw b)

In SQL Server (or any other database) you can use exists :

DELETE FROM Table_stg a
     WHERE EXISTS (SELECT 1
                   FROM Table_vw b
                   WHERE a.cid = b.cid AND a.t_date = b.t_date AND
                         a.i_location = b.location AND a.item = b.item
                  );

SQL Server doesn't allow tuples for IN .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM