Get last record from database

How can I get the last entry in the last DATE field from a MySQL database using PHP?

The rows will not match the date, so I cannot just take the first or last row.

+3
source share
4 answers

You want ORDER BY , and possibly LIMIT .

$query = 'SELECT * FROM `table` ORDER BY `date` DESC LIMIT 1';
+11
source
SELECT * FROM [Table] ORDER BY [dateColumn] DESC

If you want only the first line:

In T-SQL:

SELECT TOP(1) * FROM [Table] ORDER BY [dateColumn] DESC

In MySQL:

SELECT * FROM `Table` ORDER BY `dateColumn` DESC LIMIT 1
+1
source

LIMIT ORDER BY.

:

SELECT * FROM entries ORDER BY timestamp DESC LIMIT 1
0

, ? , , , . , ?

SELECT * FROM table ORDER BY recno DESC LIMIT 1;

SELECT * FROM table ORDER BY date_revised DESC LIMIT 1;

Thus, the PHP call will look like this:

$result = mysql_query("SELECT * FROM table ORDER BY date_revised DESC LIMIT 1");

- Nicholas

0
source

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


All Articles