I have something like the following set of tables in a DERBY db, where a PAIR row represents multiple rows in the PERSON table, a SUBGROUP represents multiple rows in the PAIR table, and a SUPERGROUP represents multiple rows in the SUBGROUP table.
<table>
<name>SUPERGROUP</name>
<column>
<name>SUPERGROUPID</name>
</column>
</table>
<table>
<name>SUBGROUP</name>
<column>
<name>SUBGROUPID</name>
</column>
<column>
<name> SUPERGROUPID </name>
</column>
</table>
<table>
<name>PAIR</name>
<column>
<name>PERSONID1</name>
</column>
<column>
<name>PERSONID2</name>
</column>
<column>
<name> SUPERGROUPID </name>
</column>
<column>
<name> SUBGROUPID </name>
</column>
</table>
<table>
<name>PERSON</name>
<column>
<name>PERSONID</name>
</column>
<column>
<name> SUPERGROUPID </name>
</column>
<column>
<name> SUBGROUPID </name>
</column>
</table>
I want to be able to delete an SUBGROUP row and all entries in the PAIR table and PERSON table that are in that SUBGROUP and the SUBGROUP's SUPERGROUP (don't want to delete rows if the same subgroup id exists in a different supergroup).
I've tried to do an Inner join described in previous posts like the following but SQuirrel SQL is giving an SQLState:42X01 ErrorCode:30000 syntax error on the command after SUBGROUP.
DELETE FROM
SUBGROUP,
PAIR,
PERSON USING SUBGROUP
INNER JOIN PAIR
INNER JOIN PERSON
WHERE
SUBGROUP.SUBGROUPID = '1'
AND SUBGROUP.SUBGROUPID = PAIR.SUBGROUPID
AND SUBGROUP.SUBGROUPID = PERSON.SUBGROUPDID
AND SUBGROUP.SUPERGROUPID = 'S1'
AND SUBGROUP.SUPERGROUPID = PAIR.SUPERGROUPID
AND SUBGROUP.SUPERGROUPID = PERSON.SUPERGROUPID
Is the above correct? Is there a better way to do it?
Also, is there a way to create a single SQL statement if I have multiple SUBGROUPs that I want to delete. ie. I want to delete SUBGROUPs {1,2,3,4,7,10} in SUPERGROUP S1?
Today I'm deleting one row at a time across all the tables but this is taking far too long when deleting 1000s of SUBGROUPs.