How do you get the last added record/row to the database in MySQL. I have to know this because I only want to update the last added row to the database.
if you have an auto-incrementing id you can do this
select * from your_table order by id desc limit 1
or even simpler
select max(id) from your_table
generally if you have a column in your table that indicates what your last record is do
select max(column_that_indicates_order) from your_table
if you do not have any column indicating what your last record was then you can't find it. Just selecting the first element without any order will not give the lastest entry last.
To update your last record you can do this:
UPDATE tblPlaces SET lat = '%s', lng = '%s'
order by id desc
limit 1
Assuming you have an ID column within your table you would do this by:
SELECT id FROM table ORDER BY id DESC LIMIT 1;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With