Home  >  Article  >  Database  >  MySQL query to get results from multiple select statements?

MySQL query to get results from multiple select statements?

王林
王林forward
2023-09-10 12:21:021065browse

MySQL query to get results from multiple select statements?

To get results from multiple select statements, use UNION ALL. Following is the syntax -

select yourValue1 AS anyColumnName
UNION ALL
select yourValue2 AS yourColumnName
.
.
.
.
N

Let us implement the above syntax to return an enumeration of numbers in different rows -

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;

This will produce the following output -

+------------+
| Number     |
+------------+
|        100 |
|       1000 |
|      10000 |
|     100000 |
|    1000000 |
|   10000000 |
|  100000000 |
| 1000000000 |
+------------+
8 rows in set (0.00 sec)

The above is the detailed content of MySQL query to get results from multiple select statements?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete