How to select from a set of integers in MySQL?


To select from a set of integers, you can use UNION. 

Following is the syntax −

SELECT yourValue1
UNION
SELECT yourValue2
UNION
SELECT yourValue3
UNION
SELECT yourValue4
.
.
.
.
N

Let us implement the above syntax to select from a set of integers in MySQL −

mysql> SELECT 1000
UNION
SELECT 2000
UNION
SELECT 3000
UNION
SELECT 4000
UNION
SELECT 5000
UNION
SELECT 6000
UNION
SELECT 7000;

This will produce the following output −

+------+
| 1000 |
+------+
| 1000 |
| 2000 |
| 3000 |
| 4000 |
| 5000 |
| 6000 |
| 7000 |
+------+
7 rows in set (0.03 sec)

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 30-Jul-2019

148 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements