Hi,
I have a MySQL table, each record has a "Id" field as PRIMARY KEY AUTO_INCREMENT.
I would like to write a string that returns me only the last record typed inside the table that should be the one with the higher ID number.
How can I take out only this data ?
Thanks
Fabio
assumeing you dont want:
select max(id) from yourtable;
you should check out
http://www.php.net/manual/en/function.mysql-insert-id.php
Hi! The query you want is:
"select colum_name form table_name order by id desc limit 1"
desc means descendent limit 1 means that you want just the first
(the last record, becouse of the "desc"!)
That´s all
(sory english errors, I´m from Brasil)
MySQL has a table status function that will tell you what the next value will me.
SHOW TABLE STATUS [FROM db_name] [LIKE wild]
Django
Ok, although the id auto increments, it's function is not to show the last record, but to stablish uniqueness. Try with a timestamp and a select(max) timestamp_column. Good luck.
You did pretty well; no need to apologize! :-)
it's function is not to show the last record, but to stablish uniqueness.
So? It's still guaranteed to be monotonically increasing, so why add an extra timestamp column if you don't need it? Besides, if your box is fast enough, you could get more than one row bearing the same timestamp.
select max(id) from tablename
is still your best option. better than ordering by something (descending), and limit 1. max(something) still uses the index, i think ordering will be slow, and is messy.
s
Uhh, if there is an index on column 'id', and a plain SELECT MAX(id) doesn't make use of the index (assuming the table is large enough) then the dbms is broken.