0

I have the following tables in my db (it's not complete here, but I think that's possible to understand the idea).

Articles
id
title
Author
id
name
Articles_Author
idArticle
idAuthor

I need to insert the articles and authors autoincremented id's in the table 'Articles_Author', in the same row.

When I use last_insert_rowid(), it adds in a different row.

Can someone help me?!

GabrielH
  • 21
  • 3
  • Is the table declared `WITHOUT ROWID`? And are you calling the function immediately after the insert? – Charlieface Feb 13 '21 at 21:21
  • No, it's not... Yep, I'm calling right after the insert, but after the `last_insert_rowid()` is created two rows, for each table (Articles and Author) and not one row in different columns. There's another way of doing it? – GabrielH Feb 14 '21 at 02:59
  • Well you can't use that function for two previous inserts, it will only give the most recent insert on any table. SQLite doesn't support variables, so you need to either save the first insert's ID in a temporary table, or bring it back to the client and pass it through again as a parameter – Charlieface Feb 14 '21 at 03:05
  • Does this answer your question? [Declare variable in SQLite and use it](https://stackoverflow.com/questions/7739444/declare-variable-in-sqlite-and-use-it) – Charlieface Feb 14 '21 at 03:06
  • Oh, I see.. It definitely helped! I ended up making a temporary table and managing the Id's like you said. Thanks! – GabrielH Feb 15 '21 at 08:37

0 Answers0