Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7763469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:40:02+00:00 2026-06-01T14:40:02+00:00

I’m solving www.db-class.com exercises. Even though it’s late the questions are still interesting. I

  • 0

I’m solving http://www.db-class.com exercises. Even though it’s late the questions are still interesting. I stumbled upon last task in extras and cannot figure out the solution.

The SQL scheme is as follows:

create table Movie(mID int, title text, year int, director text);
create table Reviewer(rID int, name text); 
create table Rating(rID int, mID int, stars int, ratingDate date);

The whole database can be obtainted here

The question is the following:

Q12 For each director, return the director’s name together with the
title(s) of the movie(s) they directed that received the highest
rating among all of their movies, and the value of that rating.
Ignore movies whose director is NULL.

To give more specific details what’s the problem here:

One query

select m.mid, m.title, max(r.stars) as stars 
from rating r natural join movie m 
where m.director is NOT NULL group by m.mid

returns IDs of most rated movies:

101 Gone with the Wind       4
103 The Sound of Music       3
104 E.T.                     3
107 Avatar                   5
108 Raiders of the Lost Ark  4

Another query

select m.director, max(r.stars) as stars 
from rating r natural join movie m 
where m.director is NOT NULL group by m.director 

returns names of the directors with most rated movies for them:

James Cameron       5
Robert Wise         3
Steven Spielberg    4
Victor Fleming      4

How to join the queries and get the name and stars for most rated movie for the director:

James Cameron      Avatar                   5
Robert Wise        The Sound of Music       3
Steven Spielberg   Raiders of the Lost Ark  4
Victor Fleming     Gone with the Wind       4
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T14:40:03+00:00Added an answer on June 1, 2026 at 2:40 pm

    In my opinion this is just a gretest-n-per-group problem. There is even a tag for that 🙂

    The only difference with the typical situation is that the grouping data (director) is in one table and the data used to make the comparison is in another table (stars). So, if you look in the question tagged as such you should find similar examples.

    I’d recommend you to solve it first assuming all your data is in one table (awful, but easier to solve… at least for me). And then switch to the splitted data.

    Spoiler:

    I think this is how to solve this so take a look at it only if you have already proposed a solution.

    select distinct m1.director, m1.title, r1.stars from movie m1
    join rating r1 on m1.mID = r1.mID
    left join (
        select m2.director, r2.stars from movie m2
        join rating r2 on m2.mID = r2.mID
    ) s on m1.director = s.director and r1.stars < s.stars
    where s.stars is null and m1.director is not null
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.