Im trying to create a select command to query the database I have and find different values from different tables in the database.
-
And what are all the columns on those tables?Lamak– Lamak2012-03-29 12:01:17 +00:00Commented Mar 29, 2012 at 12:01
-
This is what I have tried: SELECT Movie.title, Movie.year, Actor.firstName, Actor.lastName, Role.roleName From Movie, Actor, Role WHERE quoteID='Houston, we have a problem.'; /user1300580– user13005802012-03-29 12:09:06 +00:00Commented Mar 29, 2012 at 12:09
-
1Which table are quotes stored in? The answer from @Dor Cohen looks like the right approach but you haven't said where to find a quote for a moviekaj– kaj2012-03-29 12:10:42 +00:00Commented Mar 29, 2012 at 12:10
-
the quote from the movie comes from the Quote table and is listed as quoteCHARuser1300580– user13005802012-03-29 12:18:41 +00:00Commented Mar 29, 2012 at 12:18
Add a comment
|
1 Answer
Try the following, I change all ID columns from CHAR to NUMBER
CREATE TABLE Actor
(actorID NUMBER,
lastName CHAR(24),
firstName CHAR(24),
middleName CHAR(24),
suffix CHAR(6),
gender CHAR(1),
birthDate DATE,
deathDate DATE)
/
CREATE TABLE Movie
(movieID NUMBER,
title CHAR(36),
year NUMBER,
company CHAR(50),
totalNoms NUMBER,
awardsWon NUMBER,
DVDPrice NUMBER(5,2),
discountPrice NUMBER(5,2))
/
CREATE TABLE Role
(roleID NUMER,
roleName CHAR(36),
gender CHAR(1),
actorID NUMBER,
movieID NUMBER)
/
CREATE TABLE Quote
(quoteID NUMBER,
quoteCHAR CHAR(255))
/
CREATE TABLE RoleQuote
(roleID NUMBER,
quoteID NUMBER)
/
and the select will be:
SELECT Movie.Title , Movie.Year , Actor.Firstname, Actor.lastname, Role.roleName, Quote.quoteCHAR
FROM Movie, Actor, Role, Quote, RoleQuote
WHERE Movie.movieID = Role.movieId AND
Actor.actorID = Role.ActorId AND
Role.roleID = RoleQuote.roleID AND
Quote.quoteID = RoleQuote.quoteID AND
Quote.quoteCHAR LIKE '%Houston, we have a problem.%'
7 Comments
Mike Sherrill 'Cat Recall'
I'd hope schools are teaching INNER JOIN syntax by now. It's 2012, after all.
user1300580
This is what I have been working on no idea if its close but from what I am aware I am sure it is not necessary to add the two tables you are suggesting: SELECT Movie.title, Movie.year, Actor.firstName, Actor.lastName, Role.roleName FROM Movie, Actor, Role WHERE Quote.quoteCHAR ='Houston, we have a problem.'; /
Dor Cohen
How you connect between movie and Actor? is there only one movie per actor?
user1300580
SELECT Movie.title, Movie.year, Actor.firstName, Actor.lastName, Quote.quoteCHAR, Role.roleName FROM Movie, Actor, Quote, Role WHERE Quote.quoteCHAR ='Houston, we have a problem.'; / when I use the above it makes it go crazy and doesnt stop listing things
Dor Cohen
It's because you have Cartesian product you have to perform JOIN on this table by related columnms
|