Use last inserted ID in another table
Depends on the SQL implementation, I don't know any general solution.

Here someone asked for the implementation of this in a Microsoft SQL Server:
https://stackoverflow.com/questions/5228780/how-to-get-last-inserted-id

PostgreSQL:

currval('SEQUENCE_IDENTIFIER'::regclass)


In PostgreSQL, the IDs come from "SEQUENCES", and you could use the following as documented in https://www.postgresql.org/docs/8.2/static/functions-sequence.html . Note that this only works if "nextval" has been called in this session, which is also mentioned in the link.

MySQL: (https://stackoverflow.com/questions/3837990/last-insert-id-mysql)

LAST_INSERT_ID()


Suit yourself.