1

考虑这个 SQL:

SELECT c1 AS C1, 
       1  AS NO 
FROM   t1 
WHERE  c1 = 'abc' 
UNION 
SELECT c1 AS C1, 
       2  AS NO 
FROM   t2 
ORDER  BY NO 

您可能会注意到,union 之前的第一个 select 语句只是绕过向第二个查询返回的列表添加新值。

有没有办法不参与t1查询?我觉得这是不必要的,但我无法用这个查询做任何更好的事情。

结果:

C1    |NO
---------------
abc   |1
def   |2
ghi   |2
jkl   |2
mno   |2
etc   |2
---------------
4

1 回答 1

5

添加1 AS NO时,您可以添加'abc' AS C1

SELECT 'abc' AS C1, 
        1 AS NO 
   FROM DUAL
UNION 
SELECT c1 AS C1, 
       2 AS NO 
   FROM t2 
ORDER BY NO;
于 2013-03-13T10:53:06.863 回答