Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2009
    Posts
    1

    Unanswered: Delete from select criteria

    SELECT a.* FROM table1 a
    LEFT OUTER JOIN table1 b ON a.propertyID = b.propertyID
    AND a.userID = b.userID AND b.roleID IS NOT NULL
    WHERE b.propertyID IS NULL AND a.roleID IS NULL

    This is my query which returns me some records and I want to delete only these records from the same table(table1)
    How should I write my delete query

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    remove this: SELECT a.*

    add this: DELETE a FROM table1 a
    LEFT OUTER JOIN table1 b ON a.propertyID = b.propertyID
    AND a.userID = b.userID AND b.roleID IS NOT NULL
    WHERE b.propertyID IS NULL AND a.roleID IS NULL
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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