In pset7/movies, I want to dynamically exclude Kevin Bacon from the resulting list (e.g. not specifically mentioning his name with
EXCEPT or copying and pasting code that calculates his ID, so that it works for any name, entered in one place, not hard-coded).
I'm guessing that I'd need to somehow save the result of a
So, can I, for instance, save the result of this operation and use it later? I've tried
INTO but could never get the syntax right.
SELECT id FROM people WHERE name = "Kevin Bacon" AND birth = 1958
(If so, can this be done on a nested operation as well?)
Thanks in advance!
Update: I've found a way to deal with my problem, however CS50 doesn't accept it, since it requires multiple SQL statements (separated by
;)—I'm getting a "too many statements at once" error, so if anybody has a better solution (especially runtime-wise), you're more than welcome to share it.
One way to solve the problem is to create a table, for instance:
CREATE TABLE starID AS SELECT id FROM people WHERE name = "Kevin Bacon" AND birth = 1958;
and drop it afterwards:
DROP TABLE starID;