|
-
Mar 22nd, 2009, 01:44 PM
#1
Thread Starter
Addicted Member
[RESOLVED] SQL SELECT queries question
i need to show title, year of movies and order them by rank. ive tried:
Select title, year FROM movies, ratings ORDER BY rank;
it works but everything is listed 4 times. anyone know why?
Last edited by MoE70; Mar 23rd, 2009 at 10:19 AM.
-
Mar 22nd, 2009, 02:10 PM
#2
Re: SQL SELECT queries question
Use a JOIN.
SELECT title, year
FROM movies
INNER JOIN ratings on movies.movieid=ratings.movieid
ORDER BY rank
-
Mar 22nd, 2009, 02:17 PM
#3
Thread Starter
Addicted Member
Re: SQL SELECT queries question
-
Mar 22nd, 2009, 02:30 PM
#4
Re: SQL SELECT queries question
9) Show the names of all the actors who have not worked with director ‘Paul Greengrass’.
SELECT * FROM actors where actorid not in
(SELECT movie2actors.actorid FROM movie2actors
INNER JOIN movies2directors ON movie2actors.movieid=movies2directors.movieid
INNER JOIN directors ON movies2directors.directorid=directors.directorid
where directors.name = 'Paul Greengrass')
-
Mar 22nd, 2009, 02:35 PM
#5
Re: SQL SELECT queries question
10) Show the names of actors who have worked in movies with a rank in the top 10 inclusive.
Show the movie titles worked in and rank. Sort in descending order of rank.
SELECT TOP 10 actors.*, movies.title
FROM actors
INNER JOIN movies on movies.movieid=actors.movieid
INNER JOIN ratings on movies.movieid=ratings.movieid
ORDER BY ratings.rank DESC
-
Mar 22nd, 2009, 02:50 PM
#6
Thread Starter
Addicted Member
Re: SQL SELECT queries question
9) works great thanks
 Originally Posted by Pradeep1210
SELECT TOP 10 actors.*, movies.title
FROM actors
INNER JOIN movies on movies.movieid=actors.movieid
INNER JOIN ratings on movies.movieid=ratings.movieid
ORDER BY ratings.rank DESC
getting syntax errors here for Q10
mysql> SELECT TOP 4 actors.*, movies.title
-> FROM actors
-> INNER JOIN movies on movies.movieid=actors.movieid
-> INNER JOIN ratings on movies.movieid=ratings.movieid
-> ORDER BY ratings.rank DESC;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '4 act
ors.*, movies.title
FROM actors
INNER JOIN movies on movies.movieid=actors.' at line 1
mysql>
-
Mar 22nd, 2009, 03:03 PM
#7
Re: SQL SELECT queries question
Try this:
SELECT TOP 10 actors.actorid, actors.name, actors.sex, movies.title
FROM actors
INNER JOIN movie2actors ON movie2actors.actorid=actors.actorid
INNER JOIN movies on movies.movieid=movie2actors.movieid
INNER JOIN ratings on movies.movieid=ratings.movieid
ORDER BY ratings.rank DESC
-
Mar 22nd, 2009, 03:07 PM
#8
Thread Starter
Addicted Member
Re: SQL SELECT queries question
 Originally Posted by Pradeep1210
Try this:
SELECT TOP 10 actors.actorid, actors.name, actors.sex, movies.title
FROM actors
INNER JOIN movie2actors ON movie2actors.actorid=actors.actorid
INNER JOIN movies on movies.movieid=movie2actors.movieid
INNER JOIN ratings on movies.movieid=ratings.movieid
ORDER BY ratings.rank DESC
that does work either. do you want to try it on my DB its pretty small heres the SQL attached to construct it
Last edited by MoE70; Mar 23rd, 2009 at 10:18 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|