Does MySQL SQL get the most recent records in a table?

I have a sql statement as shown below to get the latest records in a table. I have two questions:

  • Is it better to order by id or by date?

  • How do I rewrite this sql statement to re-order by date?

    SELECT id, comment, DATE_FORMAT(entry_date, '%W %H:%i') FROM comments ORDER BY id DESC LIMIT 10
    
+3
source share
2 answers

It depends on what you mean by the latter:

If you mean the most recently created record, then (in most cases) using the primary key identifier will work.

If you mean the latest updated record, then definitely by date.

To sort by date, just change the field name: ORDER BY entry_date DESC

+5
source

100% , . , , , , , id-s.

id . , , , , . , id (6,7,8, -7, -6...), id, , id date.

0

Source: https://habr.com/ru/post/1728807/


All Articles