我有两个配置单元数据库db1和db2。我在db1中有一个名为table1的表,在db2中有一个名为table2的表。我想根据table1中的特定列值删除table2中的某些行。
我使用以下查询,但失败
DELETE FROM db2.table2
WHERE db2.table2.F_SESSION IN (
SELECT F_SESSION FROM db1.table1
WHERE db1.table1.STATUS = 1);
错误是
Error while compiling statement: FAILED: SemanticException [Error 10004]: Line 4:12 Invalid table alias or column reference 'db1': (possible column names are: f_session, status)
关于我哪里出错的任何线索?顺便说一下,我不是一个经验丰富的SQL人员。
答案 0 :(得分:0)
试试这个,
DELETE FROM db2..table2
WHERE db2..table2.F_SESSION IN (
SELECT F_SESSION FROM db1..table1
WHERE db1..table1.STATUS = 1);
答案 1 :(得分:0)
但这有效
USE db2;
DELETE FROM table2 WHERE table2.F_SESSION IN (
SELECT F_SESSION FROM db1.table1 AS T1
WHERE T1.STATUS = 1);