How to show a row of a table first?

1

Having this table as I would do so that row number 3 appears first in a query and the rest is like this .. but in the query all records appear, just vary the order

I would like the result of the consultation to be something like this

    
asked by Miguel Quispe 11.11.2018 в 20:36
source

2 answers

1

You can establish an arbitrary order by doing this:

SELECT * 
FROM tuTabla 
ORDER BY (id_carrera=3) DESC;

If for example, you want all the others ordered, except that, you can do:

SELECT * 
FROM tuTabla 
ORDER BY (id_carrera=3) DESC, id_carrera;

Or also set another order for another column, always having the 3 in first:

SELECT * 
FROM tuTabla 
ORDER BY (id_carrera=3) DESC, nombre;
    
answered by 11.11.2018 в 21:00
0

Maybe I can help you using the "UNION" operator, in a first consultation you extract the row with id 3, in a second query you extract all the rows with identifier other than 3 and you order them up by id, to later use UNION operator and join the results of both queries and get what you want.

 ( SELECT *
   FROM tuTabla
   WHERE id = 3
 )
 UNION
 (
   SELECT * 
   FROM tuTabla
   WHERE id != 3
   ORDER BY id ASC
 )
    
answered by 11.11.2018 в 22:53