Among other questions, this one asked how to delete from a join.
My question: How much of this is standard SQL? On which databases would this actually work (most not
The Standard SQL-92 syntax required a scalar subquery. This is a relationally solid solution because there is no ambiguity (unlike the proprietary alternatives which can yield unpredictable/unexpected results).
However, one of the drawbacks of the SQL-92 approach is that it can be verbose and involve repetitive constructs e.g.
UPDATE MyTable
SET col1 = (
SELECT T.colA
FROM OtherTable T
WHERE T.ID = MyTable.ID
),
col2 = (
SELECT T.colB
FROM OtherTable T
WHERE T.ID = MyTable.ID
)
WHERE EXISTS (
SELECT *
FROM OtherTable T
WHERE T.ID = MyTable.ID
);
The idea is that the optimizer can recognize the same subquery being reused but in practice vendors have typically not implemented this.
SQL-99 addressed this verbosity and repetition by introducing MERGE
, which was further refined in SQL:2003. It is interesting that nowadays the vendors typically choose to implement new features as per the Standard spec then extend them to provide the features they require, rather than writing wholly proprietary features.