Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2002
    Location
    Chicago area
    Posts
    8

    Unanswered: SQL Help - Delete Query

    I'm relatively new to SQL and am trying to delete all rows in ADDRESS where the ADDRESSID (primary key of ADDRESS) is on multiple rows on table2

    DELETE FROM ADDRESS
    WHERE ADDRESSID =
    (SELECT DISTINCT ADDRESSID
    FROM ADDRLINKRECORD
    WHERE CUSTOMERARC = 'Y')

    I am receiving the message:

    DB21034E The command was processed as an SQL statement because it was not a valid Command Line Processor command. During SQL processing it returned: SQL0811N The result of a scalar fullselect, SELECT INTO statement, or VALUES INTO statement is more than one row. SQLSTATE=21000

    Could someone give me a little assistance?

    I'd prefer to perform this in "pure SQL" but if I need to open a cursor and process each delete singlely, I can do that. Just looking for the fastest/easiest way to accomplish this.

    TIA
    -jP

  2. #2
    Join Date
    Jan 2002
    Location
    India
    Posts
    17
    Try grouping the subselect on Addressid
    Or else use in clause . So your query looks somewhat like this :

    DELETE FROM ADDRESS WHERE ADDRESSID in (SELECT DISTINCT ADDRESSID FROM ADDRLINKRECORD WHERE CUSTOMERARC = 'Y')

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •