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

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

    in this scenario:

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

    aren't you missing the column you want to compare to? example:

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

    I assume it's that column since in your select statement you're selecting from the same table you're wanting to delete from with that column.

提交回复
热议问题