-3

Possible Duplicate:
How to get ID of the last updated row in MySQL?

I have table that I call VAUCER, and inside have rows ID, BROJ, TEKST, DATUM, VREME

ID is primary index AI, BROJ is some number, TEKST is TXT, DATUM is DATE, and VREME is some number, I have made that to be time();

I want to display only one last edited record, not all records, how to mysql query that?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Tanja Pakovic
  • 193
  • 1
  • 3
  • 14

5 Answers5

0

Assuming DATUM which is of type DATE have the date of the last editing time, then you could do:

select * from VAUCER order by DATUM desc LIMIT 1
Nelson
  • 49,283
  • 8
  • 68
  • 81
0

Is DATE or VREME values updated each time row is updated?

Try this: SELECT * FROM VAUCER ORDER BY DATUM DESC LIMIT 1

Bogdan Burym
  • 5,482
  • 2
  • 27
  • 46
0

assuming that DATUM updates on every change

SELECT * FROM `VAUCER` ORDER BY `DATUM` DESC LIMIT 1
0

It is easy to do with a TIMESTAMP column in the table. Add new TIMESTAMP column defined as ON UPDATE CURRENT_TIMESTAMP:

ALTER TABLE VAUCER
  ADD COLUMN time_stamp_field TIMESTAMP DEFAULT CURRENT_TIMESTAMP
  ON UPDATE CURRENT_TIMESTAMP

MySQL will write current datetime to the cell on any update, then you can easily find last edited record:

select * from VAUCER order by time_stamp_field desc limit 1
amk
  • 284
  • 1
  • 3
0

Here is the anwser to display last edited id from table add new row NOW and make it datetime When inserting in table make

 $now=date("Y-m-d H:i:s");

and insert in $now in row NOW

When mysql query do this

SELECT * FROM SOMETABLE ORDER BY NOW DESC LIMIT 1;
Tanja Pakovic
  • 193
  • 1
  • 3
  • 14