You can use the php function mysql_insert_id() to get the id mysql id of the last inserted record through that database connection irrespective of the table.
For eg, to the table customers(id, name)
db_query("insert into customers set name='myname'");
$id = mysql_insert_id();
/** $id will...