基本上可以对表和筛选器行执行完全联接,其中任何表的id都为null。假设您有两个名为temp\u table1和temp\u table2的表,下面的查询应该可以工作: select*from(select(case when temp_table1.id is null then temp_table2.id when temp_table2.id is null then temp_table1.id else null end)as id from temp_table1 full join temp_table2 on temp_table1.id=temp_table2.id)q1其中id不为null; 说明:首先,我对这两个表执行完全联接,以获得与这两个表对应的所有行。 如果条件是我正在检查,如果id在表1中为null,那么我们将从表2中返回id。 类似地,如果表2中的id为null,我们将从表1返回id。如果它在任何表中都不是null,那么我们将返回null。 最后,我们将其放入子查询中,并返回返回id不为null的行。希望这有帮助。
3条答案
按热度按时间b5lpy0ml1#
正如@drago所回答的,在这种情况下,外部连接应该是足够有效的!
rjee0c152#
基本上可以对表和筛选器行执行完全联接,其中任何表的id都为null。假设您有两个名为temp\u table1和temp\u table2的表,下面的查询应该可以工作:
select*from(select(case when temp_table1.id is null then temp_table2.id when temp_table2.id is null then temp_table1.id else null end)as id from temp_table1 full join temp_table2 on temp_table1.id=temp_table2.id)q1其中id不为null;
说明:首先,我对这两个表执行完全联接,以获得与这两个表对应的所有行。
如果条件是我正在检查,如果id在表1中为null,那么我们将从表2中返回id。
类似地,如果表2中的id为null,我们将从表1返回id。如果它在任何表中都不是null,那么我们将返回null。
最后,我们将其放入子查询中,并返回返回id不为null的行。希望这有帮助。
9fkzdhlc3#
从table1中选择a.id a left outer join table2 b on b.id=a.id其中b.id为空;