What makes my situation tricky is that I don't have a single column key, with a simple list of primary keys to delete (for instance, "delete from table where key in ([list])"). I have multiple columns together as the primary key, and would need to join on all of them.
Using what I know of other databases, I thought this might be done as:
DELETE FROM
table1 t1
LEFT OUTER JOIN
table2 t2
ON
t2.key1 = t1.key1 AND
t2.key2 = t1.key2
WHERE
t2.key1 IS NULL;
But Teradata (v12) responds with error number 3706, saying "Syntax error: Joined Tables are not allowed in FROM clause."
Deleting rows based on another table. Sometimes we need to delete rows based on another table. This table might exist in the same database or not. We can use the table lookup method or SQL join to delete these rows.
DEL <table-name> ; In the earlier releases of Teradata, the ALL was required to delete all rows. Now, ANSI rules say that ALL is the default for all rows. The ALL is optional and with or without it, all rows are deleted.
I came to know that qualify cannot be used in delete statement.
The syntax also supports deleting rows from multiple tables at once. To delete rows from both tables where there are matching id values, name them both after the DELETE keyword: DELETE t1, t2 FROM t1 INNER JOIN t2 ON t1.id = t2.id; What if you want to delete nonmatching rows?
Found this is done by:
DELETE FROM
table1
WHERE
(key1, key2) NOT IN (
SELECT UNIQUE key1, key2 FROM table2
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With