2015-04-06 83 views
2

我寫了兩個sql select查詢並使用'union'加入它。 但輸出是混合的。我想先輸出第一個查詢,依此類推。 怎麼可能。我的SQL小提琴下面給出。SELECT USING UNION QUERY

SQLFiddle

+0

使用sqlfiddle是不錯的主意。 – 2015-04-06 06:24:08

回答

6

嘗試用union all

select SUBSTR(name, 1, 2) from customer 
union all 
select SUBSTR(name, 1, 3) from customer 
; 
+0

謝謝..它的工作.. – 2015-04-06 06:27:19

2

,如果你想先看到第一查詢。您可以使用UNION ALL

select SUBSTR(name,1, 2) from customer 
union ALL 
select SUBSTR(name,1, 3) from customer; 

如果你想通過名字來命令你可以使用

select SUBSTR(name,1, 2) from customer 
union 
select SUBSTR(name,1, 3) from customer 
order by substr;