MySQL query to get result from multiple select statements?

MySQLMySQLi Database

To get result 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 in order to return 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)
raja
Published on 03-Sep-2019 08:24:56
Advertisements