SQL to know the last edited record

Asked

Viewed 45 times

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, as I do to list in the order of editing even if it is the same day?

Example:

I have the records:

ID - Update

101 - 15.03.2016
159 - 15.03.2016
243 - 15.03.2016

Only the last one edited was ID 159 and he’s third on the list, I need him to come first.

I’m waiting for help!

  • How are you registering the exact order of the issue?

  • 1

    You are only recording the date, or date and time?

  • ORDER BY ueditado DESC

1 answer

2


From what I understand, you record the editing date in the uedita column. So if you sort by the uedita column 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 statement LIMIT.

$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 the database ueditado as date and not as timestamp, no matter the magic query you use, it will not be possible to search precisely for the last edited record.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.