It doesn't select any rows because there is no people record with both those names.
The immediate suggestion would be to use OR instead of AND.
Another option would be to use an alias of the people table to join it as "another" table, each (people and "another") joined on one of the names.
It would be easy to create a list of Johnny Depp ...
Your DISTINCT would make the result records appear only once. But that means the name, and multiple stars might share a name. In other SQL dialects you could use DISTINCT ON (col1, col2) with an "ON" and a list of columns to use for the DISTINCT, but SQLite does not seem to support such thing.
I actually solved this by applying the DISTINCT to a sub-query ...
It's because in your first query you said where id = (.... this query here is expecting only 1 value so in the query inside the parentheses the first value it gets is the only value that is checked. To make your query correct all you have to do is change the = with IN, the IN command here checks a list of values.
SELECT * FROM smth WHERE name IN ('...
Ok, nevermind i found it. It was literally a "%" after the 'Toy Story' in the last line of movies.title.
But then it printed out 'Toy Story' in the output of 4 rows instead of the people who starred. I accidentally wrote SELECT title FROM people instead of SELECT name FROM people.
Sorry for wasting your time.
I also completed pset7 recently. You can easily make this query by joining the two tables using the JOIN and ON keywords and with the id as the primary key. The code should be as follows.
SELECT title, rating FROM movies JOIN ratings ON id = movie_id WHERE year = 2010 ORDER BY rating DESC, title ASC
As for your method, I'm a beginner in SQL and I didn't even ...
You are also able to use the INTERSECT keyword.
SELECT name FROM people
WHERE name = "actor number 1"
SELECT name FROM people
WHERE name = "actor number 2"
This was the most elegant suggestion I could find online since I had the same problem...
You can redirect the output to a file and then open that and go to the bottom.
$ cat 1.sql | sqlite3 movies.db > 1.txt
alternatively, if you only want the number of rows
$ cat 1.sql | sqlite3 movies.db | wc -l
The wc -l counts the lines, that would include the header, so you would have to subtract 1 to get the number of data rows.
I just recently solved this PSET, so I'm no expert, so I'm going to try and explain what is different about what I did in comparison to what you have (meaning I can't answer the three questions you asked directly).
The biggest difference between mine and yours is that I joined the tables, which was important so that I could access the titles and ratings &...
and person_id not in (select id from people where name ="Kevin Bacon" AND birth=1958)
before the group statement.
Also, Use "select distinct" on first line in place of "select".
If this helped, please click the tickmark.
SELECT name FROM people WHERE id in (
SELECT person_id FROM stars WHERE movie_id in (
SELECT id FROM movies WHERE id in (
SELECT movie_id FROM stars WHERE person_id in (
SELECT id FROM people WHERE name = "Kevin Bacon" AND birth = 1958)))) AND name !=