A
A
Alexey Lebedev2015-07-05 09:15:23
SQL
Alexey Lebedev, 2015-07-05 09:15:23

How to output through IN values ​​in order in SQL?

SELECT * FROM table WHERE id IN(1,7,2,8,3);
It is necessary that the lines are displayed in the order specified in the id:
1 line
7 line
2 line
8 line
3 line

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yuri Chernyshev, 2015-07-05
@swanrnd

SELECT * FROM table WHERE id IN(1,7,2,8,3) ORDER BY FIELD(id,1,7,2,8,3)

M
Mokhirjon Naimov, 2015-07-05
@zvermafia

SELECT * FROM table WHERE id IN(1,7,2,8,3) ORDER BY id ASC;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question