Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2008
    Posts
    24

    Unanswered: Need help with a simple DELETE

    Hello,

    I have 2 tables:

    tableA
    --------------
    uniqueID int
    aFlag smallint

    tableB
    --------------
    uniqueID int
    <other fields ...>

    I need to delete all records in tableB for which the value of
    aFlag in tableA is 0.
    They join on uniqueID.
    Not all records in tableA have a related record in tableB.

    Thanks in advance for any input,
    chasse

  2. #2
    Join Date
    Aug 2008
    Posts
    12
    delete from tableB where uniqueID IN (select * from tableA where aFlag = 0)

  3. #3
    Join Date
    Aug 2008
    Posts
    24

    Thumbs up

    Thanks! You got me on the right track!
    delete from tableB where uniqueID IN (select uniqueID from tableA where aFlag = 0)

  4. #4
    Join Date
    Aug 2008
    Posts
    12
    Quote Originally Posted by chassemerrill
    Thanks! You got me on the right track!
    delete from tableB where uniqueID IN (select uniqueID from tableA where aFlag = 0)


    sorry my bad...i meant that

  5. #5
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    You could probably improve the performance (if required) by using EXISTS rather than IN:
    Code:
    delete from tableB 
    where  exists(
               select 1 
               from   tableA ta 
               where  ta.uniqueID  = tableB.uniqueID 
                      and ta.aFlag = 0 )

Posting Permissions

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