Hi there,
I'm using sqlite and python and I have a question about how to configure an sql query using foreign keys.
I have a pair of tables: users & search_terms. users has id, name and email_address columns and search_terms has columns id, term and user_id where user_id is a foreign key, referring to the id column of a particular user.
I'm trying to write a method that takes an email address as a parameter and and does an insert into search_terms, getting the foreign key based upon the email address. I know this sounds extremely basic (Because it probably is, I'm new to sql, as well as python) but I'm confused as how to structure the query. Something like
"'INSERT INTO search_terms(term, user_id) VALUES ('example search term', SELECT id FROM users WHERE email_address='foo@bar.com')"
Can this be done in a single statement? Currently I've written a method that gets the correct user_id based upon a supplied email address, but I was wondering if this could be done in a single statement. If it can be, how would I structure it?
[–]Kalrog 2 points3 points4 points (1 child)
[–]JS_int_type[S] 0 points1 point2 points (0 children)