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

前端 未结 5 1651
梦毁少年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:48

    Shouldn't you have:

    DELETE FROM tableA WHERE entitynum IN (...your select...)
    

    Now you just have a WHERE with no comparison:

    DELETE FROM tableA WHERE (...your select...)
    

    So your final query would look like this;

    DELETE FROM tableA WHERE entitynum IN (
        SELECT tableA.entitynum 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')
    )
    

提交回复
热议问题