I am writing a query that will select data from 3 different tables - movies, dates, and images. In the dates and movies table there will always be exactly 1 row for each movie, but in the images table there may be multiple rows for a given movie.
The results I want may contain multiple movies - all the movies that start on a specific date, but I need to limit the results to exactly one row for each movie. Right now I am getting multiple rows for the movie if I have multiple images.
For example, I want:
March2, Wild Hogs, image1
March2, Zodiac, image1
What I'm getting is
March2, Wild Hogs, image1
March2, Wild Hogs, image2
March2, Zodiac, image1
March2, Zodiac, image2
I guess I could do this by running two separate queries, but I would prefer to do it in one.
2007-02-28
13:41:21
·
3 answers
·
asked by
Justin H
7
in
Computers & Internet
➔ Programming & Design
I am trying to generate a newsletter that will include one of the images for the movie. in other places I use more than one image or a randomly selected image.
Here's the site I'm working with http://www.lakeportcinema.com
Here's my query as it stands right now:
SELECT Dates.start_date, Dates.id, Dates.nopasses, Movies.title, Movies.run_time, Movies.cast, Movies.rating, Movies.rating_reason, Movies.description, Movie_art.image_url FROM Dates, Movies, Movie_art WHERE Dates.theatre_id='$theatre_id' AND Dates.id=Movies.id AND Dates.id=Movie_art.id AND ((UNIX_TIMESTAMP(Dates.start_date) <= UNIX_TIMESTAMP('$end')) AND (UNIX_TIMESTAMP(Dates.start_date) >= UNIX_TIMESTAMP('$start'))) ORDER BY Dates.start_date DESC, Movies.title
2007-02-28
14:00:50 ·
update #1
dhvrm: thanks for the imput. It sounded good, but still returns the same results.
2007-02-28
14:37:53 ·
update #2