1

Im trying to create a select command to query the database I have and find different values from different tables in the database.

4
  • And what are all the columns on those tables? Commented 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.'; / Commented Mar 29, 2012 at 12:09
  • 1
    Which 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 movie Commented Mar 29, 2012 at 12:10
  • the quote from the movie comes from the Quote table and is listed as quoteCHAR Commented Mar 29, 2012 at 12:18

1 Answer 1

3

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.%'
Sign up to request clarification or add additional context in comments.

7 Comments

I'd hope schools are teaching INNER JOIN syntax by now. It's 2012, after all.
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.'; /
How you connect between movie and Actor? is there only one movie per actor?
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
It's because you have Cartesian product you have to perform JOIN on this table by related columnms
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.