How can I get the latest ID in a table?
IF you've just inserted into a table with auto_increment you can run right after your query.
auto_increment
SELECT last_insert_id();
Otherwise the max(id) FROM table
max(id) FROM table