How to get from last record to first

Asked

Viewed 48 times

0

I have these names on my chart:

nome
-----
A
B
C
D
E
F

If I do:

SELECT nome FROM tabela

he will return me "A, B, C, D, E, F".

I’d like you to return me backwards, from the last record to the first.

F, E, D, C, B, A.

How could I?

  • 1

    SELECT FROM table name order by DESC name

  • your question is misspelled. If the order of names is A B F C D E nor order by nome DESC nor order by id DESC will return the desired. Now, if the entry order in the table is alphabetical, either by name or DESC id

1 answer

4


You can order your return through the order by:

SELECT nome FROM tabela ORDER BY nome DESC
  • but I wouldn’t necessarily like to order them from Z to A. I would just like to take from the last record to the first.

  • then the ordination must be done by id, instead of the name? is that?? ie order from the greatest to the least id rather than alphabetical order?

  • 1

    Makes sense, I traveled kkk. Thanks!

  • @dds, one of the solutions is to use the id, if it is auto_increment, or else create a field with the registration date, but the only sorting method for what you requested is using the order by, only has to see the field(s) (s) you wish to order.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.