要從多個 select 語句中取得結果,請使用 UNION ALL。以下是語法 -
select yourValue1 AS anyColumnName UNION ALL select yourValue2 AS yourColumnName . . . . N
讓我們實作上述語法,以傳回不同行中的數字枚舉 -
mysql> select 100 AS Number UNION ALL select 1000 AS Number UNION ALL select 10000 AS Number UNION ALL select 100000 AS Number UNION ALL select 1000000 AS Number UNION ALL select 10000000 AS Number UNION ALL select 100000000 AS Number UNION ALL select 1000000000 AS Number;
這將產生以下輸出 -
+------------+ | Number | +------------+ | 100 | | 1000 | | 10000 | | 100000 | | 1000000 | | 10000000 | | 100000000 | | 1000000000 | +------------+ 8 rows in set (0.00 sec)
以上是MySQL查詢從多個select語句中取得結果?的詳細內容。更多資訊請關注PHP中文網其他相關文章!