Subqueries and Correlated Deletes
Subqueries and correlated deletes can be performed on
RWDBDeleter in a similar fashion to
RWDBSelector. Please refer to
Subqueries for the details of constructing subqueries and correlated subqueries.
Following is an example of using a subquery in an
RWDBDeleter
RWDBTable primary = myDbase.table("primary");
RWDBTable backup = myDbase.table("backup");
RWDBSelector avg = myDbase.selector(); //1
avg << rwdbAvg(backup["onHand"]);
RWDBDeleter delete = primary.deleter(); //2
delete.where(primary["onHand"] >= avg); //3
A reasonable interpretation of this code fragment could be expressed this way in SQL:
DELETE FROM primary
WHERE primary.onHand >=
(
SELECT AVG(backup.onHand)
FROM backup
)
Following is an example of correlated delete by use of a correlated subquery in an
RWDBDeleter.
RWDBTable primary = myDbase.table("primary");
RWDBTable backup = myDbase.table("backup");
RWDBSelector avg = myDbase.selector(); //1
avg << rwdbAvg(backup["onHand"]);
avg.where(backup["ID"] == primary["ID"]);
avg.fromExtern(primary);
RWDBDeleter delete = primary.deleter(); //2
delete.where(primary["onHand"] >= avg);
A reasonable interpretation of this code fragment could be expressed this way in SQL:
DELETE FROM primary
WHERE primary.onHand >=
(
SELECT AVG(backup.onHand)
FROM backup
WHERE backup.ID = primary.ID
)