How to write a SQL DELETE statement with a SELECT statement in the WHERE clause?

前端 未结 5 1656
梦毁少年i
梦毁少年i 2020-11-30 02:10

Database: Sybase Advantage 11

On my quest to normalize data, I am trying to delete the results I get from this SELECT statement:

SELECT          


        
5条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-30 02:42

    You need to identify the primary key in TableA in order to delete the correct record. The primary key may be a single column or a combination of several columns that uniquely identifies a row in the table. If there is no primary key, then the ROWID pseudo column may be used as the primary key.

    DELETE FROM tableA
    WHERE ROWID IN 
      ( SELECT q.ROWID
        FROM tableA q
          INNER JOIN tableB u on (u.qlabel = q.entityrole AND u.fieldnum = q.fieldnum) 
        WHERE (LENGTH(q.memotext) NOT IN (8,9,10) OR q.memotext NOT LIKE '%/%/%')
          AND (u.FldFormat = 'Date'));
    

提交回复
热议问题