A
A
Artem2015-12-31 09:20:25
PHP
Artem, 2015-12-31 09:20:25

How to get last x rows from mysql?

Hello!
I have the following table in the database:
61527faf43e74d669eb6df5d51e4584c.png
I saw in Google that you can query the last x rows by id, but I don’t have an id field, can I use the DATETIME field instead?
Thanks in advance for the
UPD answer.
The query returns 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DESC BY `Date` LIMIT 10' at line 1
UPD2. The solution I found on the
Request structure had to be done a little different:

SELECT * FROM 'table_name' ORDER BY 'Дата' DESC LIMIT 10;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Valery Ryaboshapko, 2015-12-31
@proudmore

SELECT * FROM `имя_таблицы` ORDER BY `Дата` DESC LIMIT 10;

And if you need exactly the last x in chronological order, then sorting by the date field is the only correct solution, because no one guarantees that the id is tied to the chronology. For example, weather data may have been added "backdated".
UPD. Indeed, I made a mistake in the answer, I corrected it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question