我有一个查询,我在其中构建一个值表,并将其与另一个查询联合起来。我希望返回一组结果,其中两个表之间的一个值不匹配。 (下面的查询示例)。每次我尝试执行时,都会遇到可怕的无效标识符错误,但我不知道为什么。任何建议将不胜感激!
select * from (
select '1234567' as empno, 'A' as status, 'Active' as st_name from dual union all
select '89012345' as empno, 'DA' as status, 'Inactive' as st_name from dual) ft
union
select id,status,statusnm from second_table st
where st.id = ft.empno
and st.statusnm <> ft.st_name;
有任何想法/建议吗?
答案 0 :(得分:1)
你不想要union
,你想要join
。 。 。它应该是明确的:
select st.*
from (select '1234567' as empno, 'A' as status, 'Active' as st_name from dual
union all
select '89012345' as empno, 'DA' as status, 'Inactive' as st_name from dual
) ft join
second_table st
on st.id = ft.empno and st.statusnm <> ft.st_name