#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    35
    Rep Power
    2

    Deleting rows from table, using parent-child relationship


    Hi there,

    I have a table, tableA, that contains one column, data type integer, that has a unique index for each row, and a few other columns that aren't important. Then I also have another table, tableB, with two columns, both integer types, named parent and child, that correspond to parent-child relationships between the indexes used in tableA.

    Now I need to delete some rows from tableA. If I have two rows that have the same values for all columns except for the index, and where the two indexes are in a parent-child relationship, as found in tableB, then I need to delete the row with the child index and leave the row with the parent index alone. It seems to be necessary to use JOIN for the SQL statement, but I can't figure out how to put it together to delete the children rows only.
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,235
    Rep Power
    4279
    joined DELETE syntax is notoriously inconsistent between various database systems

    you neglected to mention which one you're using
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

IMN logo majestic logo threadwatch logo seochat tools logo