I'm new to SQL and C# and am currently trying to create a library software. I'm facing a bit of a problem and would appreciate your input.
I have three tables:
- Books (
BookID, Title) - Author (
AuthorID, AuthorFname, AuthorLname) - WrittenBy (
BookID, AuthorID)
BookId in the table Books and AuthorID in the table Author are indexed and are the primary keys.
What I need to do is,
- get the bookId from the books table,
- get the authorID from the author table,
- insert these two values into the writtenby table
My solution is to write two separate SQL statements to select the id columns and then enter it into the third table.
But what if there are two books with the same title?
Is there a way to get the last inserted values in SQL?