Show last or first posts

How to query a MySQL database to display the latest or first records?


Answer 1, authority 100%

Using sorting and limited output.

SELECT * FROM table_name ORDER BY id LIMIT 1

returns the first entry

SELECT * FROM table_name ORDER BY id DESC LIMIT 1

return the last entry


Answer 2, authority 67%

Use the desk or asc function. Example

SELECT name, id FROM peoples ORDER BY id DESC
SELECT name, id FROM peoples ORDER BY id ASC