select *
from
{
SELECT
ID, CLASS, CHANGE_NUMBER AS OBJECT_NUMBER
FROM table_A
UNION
SELECT
ID, CLASS, CUST_NO AS OBJECT_NUMBER
FROM table_B
ORDER BY ID
} x where x.id ='5434';
帮我运行此查询。
我收到错误“无效的表名”
答案 0 :(得分:3)
我建议像这样编写查询:
select x.*
from (SELECT ID, CLASS, CHANGE_NUMBER AS OBJECT_NUMBER FROM table_A
UNION ALL
SELECT ID, CLASS, CUST_NO AS OBJECT_NUMBER FROM table_B
) x
where x.id = '5434';
注意:
UNION ALL
代替UNION
,除非您真的想要承担删除重复项的开销。ORDER BY
。毕竟,您只选择一个id
。ORDER BY
,最好将它放在外部查询中而不是子查询中。答案 1 :(得分:1)
使用'('括号代替' {'。
EditText