Reputation:
If two individual records are added to a database such as two patients being added to the table 'Paitents' and when they are added the Primary_Key such as Paitient_ID is created automatically and given to each new account. .(Auto Incremented) That bit is quite straight forward and understand I can just use an 'INSERT INTO SONGS' statement. But what if the two patients are related and I have another table called "Relations" Where by I need it to pull in the two Paitent_ID's and create a relation from the same insert query. Can this be done?
Upvotes: 0
Views: 53
Reputation: 1779
ID generated by MySQL automatically in auto_increment
column can be obtained using the LAST_INSERT_ID()
function. Languages/libraries often offer a function for this (e.g. in PHP PDO you call PDO::lastInsertId()
instead of making another query).
How to solve this exactly depends on how you are inserting the values into a database, but the basics can be:
Upvotes: 1