Please excuse any syntax errors in my examples; I am new to SQL. For this question, let us suppose I have this hypothetical structure:
authors_list:
- author_id INT NOT_NULL AUTO_INCREMENT PRIMARY
- author_name VARCHAR(30) NOT_NULL
books_list:
- book_id INT NOT_NULL AUTO_INCREMENT PRIMARY
- book_author_id INT NOT_NULL FOREIGN_KEY(authors_list.author_id)
- book_name VARCHAR(30) NOT_NULL
Generally when importing books, I would only know the book name and author name. I have finally figured out how to insert into books_list
using only this data:
INSERT INTO `books_list`(`book_author_id`, `book_name`) VALUES ((SELECT `author_id` FROM `authors_list` WHERE `author_name` = 'SomeAuthorName'), 'SomeBookName')
However, I have a .csv file which only contains the columns author_name
and book_name
. I have previously been importing .csv files with phpMyAdmin, but those tables did not have foreign keys. Is there any way to import a .csv of the form described using this "on the fly lookup" functionality?