D
D
dNertyco2021-07-27 22:59:34
SQL
dNertyco, 2021-07-27 22:59:34

How to select values ​​from the table, while returning the first record with a certain id in the response?

There is id = let's say 17
And there is a query
SELECT `id`,`value` FROM `table`
The answer looks like this:
id value
1 556
6 4442
17 2242
34 22242
You need to use sql to put the record with id 17 in the first place in the response

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Slava Rozhnev, 2021-07-27
@dNertyco

SELECT `id`,`value` FROM `table` ORDER BY `id` = 17 DESC;

B
BasiC2k, 2021-07-27
@BasiC2k

You make one more field in the resulting query, which is True for id=17 and False otherwise. Then sort by that field.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question