SQL to know which last edited record

1

I have the following SQL:

$dcadastroultimo = date("d.m.y");
$sqlidcidade = "select id, titulo, tipo from imoveis where cod = '$cliente' AND
ueditado <= '$dcadastroultimo' ORDER BY id ASC";

I need you to list the last edited records, but several are edited with the date of the same day, how do I list in the same editing order being same day?

Exceptions:

I have the records:

ID - Update

101 - 15.03.2016
159 - 15.03.2016
243 - 15.03.2016

Only the last edit was ID 159 and it's the third one on the list, so I need to get it first.

I look forward to helping you!

    
asked by anonymous 15.03.2016 / 18:13

1 answer

2

From what I understand, you record the edit date in the column you've read. So if you sort by the column you used in descending order.

$sqlidcidade = "select id, titulo, tipo from imoveis where cod = '$cliente' ORDER BY ueditado DESC";

If you only want the latter, you can use the LIMIT statement.

$sqlidcidade = "select id, titulo, tipo from imoveis where cod = '$cliente' ORDER BY ueditado DESC LIMIT 1";

LIMIT 1 causes only the first record found to be returned.

Important detail: If you are storing in database ueditado as date and not as timestamp, no matter what query magic you use, it will not be possible accurately search for the last edited record.

    
15.03.2016 / 18:23