How should I join these 3 SQL queries in Oracle?

Posted by Nazgulled on Stack Overflow See other posts from Stack Overflow or by Nazgulled
Published on 2011-01-03T15:28:24Z Indexed on 2011/01/03 15:53 UTC
Read the original article Hit count: 232

Filed under:
|
|
|

I have these 3 queries:

SELECT
  title, year, MovieGenres(m.mid) genres,
  MovieDirectors(m.mid) directors, MovieWriters(m.mid) writers,
  synopsis, poster_url
FROM movies m
WHERE m.mid = 1;

SELECT AVG(rating) FROM movie_ratings WHERE mid = 1;

SELECT COUNT(rating) FROM movie_ratings WHERE mid = 1;

And I need to join them into a single query. I was able to do it like this:

SELECT
  title, year, MovieGenres(m.mid) genres,
  MovieDirectors(m.mid) directors, MovieWriters(m.mid) writers,
  synopsis, poster_url, AVG(rating) average, COUNT(rating) count
FROM movies m INNER JOIN movie_ratings mr
  ON m.mid = mr.mid
WHERE m.mid = 1
GROUP BY
  title, year, MovieGenres(m.mid), MovieDirectors(m.mid),
  MovieWriters(m.mid), synopsis, poster_url;

But I don't really like that "huge" GROUP BY, is there a simpler way to do it?

© Stack Overflow or respective owner

Related posts about sql

Related posts about Oracle