Home > Database > Mysql Tutorial > body text

MySQL query to get results from multiple select statements?

王林
Release: 2023-09-10 12:21:02
forward
1085 people have browsed it

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
Copy after login

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;
Copy after login

This will produce the following output -

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

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template