Cross-query with IN/INTERSECT, INNER JOIN or EXISTS?
You'll get the same results from all three. I would recommend the INNER JOIN
, as it's the simplest to write. The gains in performance will be probably always be negligible, but queries 2 and 3 will require one less index scan. Query 1 will scan cast_info twice.
To update the table after, you can do something like this:
UPDATE PSET P.Person_Name = T.Person_NameFROM Person PINNER JOIN OtherTable T on T.Person_ID = P.Person_ID
And of course, it's always nice to run a SELECT
, verify your columns, then change the first two lines to be an update and fire away with confidence.
SELECT P.Person_ID, P.Person_Name, T.Person_ID, T.Person_NameFROM Person PINNER JOIN OtherTable T on T.Person_ID = P.Person_ID
This intersect is redundant
WHERE movie_id IN ( SELECT movie_id FROM cast_info INTERSECT SELECT movie_id FROM movie );
I think the join is the most direct
INSERT INTO person (person_id)SELECT DISTINCT person_idFROM cast_infoINNER JOIN movieON cast_info.movie_id=movie.movie_id;
why?
CREATE TABLE person( id INTEGER PRIMARY KEY AUTOINCREMENT
just use person_id as primary key
and use date for birthday