如何删除 Teradata 表中不在另一个表中的行?
让我的情况变得棘手的是,我没有单个列键,只有一个要删除的简单主键列表(例如,“从表中删除([列表])”)。我有多个列作为主键,并且需要加入所有列。
根据我对其他数据库的了解,我认为这可能会这样做:
DELETE FROM
table1 t1
LEFT OUTER JOIN
table2 t2
ON
t2.key1 = t1.key1 AND
t2.key2 = t1.key2
WHERE
t2.key1 IS NULL;
但 Teradata (v12) 响应错误号 3706,指出“语法错误:FROM 子句中不允许使用连接表”。
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."
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
发现这是通过以下方式完成的:
Found this is done by:
另一种方法是使用相关子查询:
Another way is to use a correlated subquery: