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 7648757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:47:49+00:00 2026-05-31T10:47:49+00:00

NOTE: I accidentally put another question’s sentence in here (massive apologies on my part),

  • 0

NOTE: I accidentally put another question’s sentence in here (massive apologies on my part), I have updated this post as of Wednesday 14th March at 23:21pm with the correct question.

I have spent a few hours trying to figure out this question without anyone’s help but have realised I have wasted too much productive time and should’ve asked someone sooner. I had a decent crack at this and have come so close but cannot get the final solution I need. What I am supposed to get is:

For all cases where the same reviewer rated the same movie twice and
gave it a higher rating the second time, return the reviewer’s name
and the title of the movie.

This is the query I managed to get here:

SELECT reviewer.name, movie.title, rating.stars  
FROM (reviewer JOIN rating ON reviewer.rid = rating.rid)  
JOIN movie ON movie.mid = rating.mid  
GROUP BY reviewer.name 
HAVING COUNT(*) >= 2  
ORDER BY reviewer.name DESC

(I have a feeling there is a missing WHERE clause from the above query, but am not sure where to place it)

(From what I have learned, RIGHT and FULL OUTER JOINs are not currently supported in SQLite)

And here are the tables and data (in pictures)…

Movie

Reviewer

Rating

… And the DB code…

/* Delete the tables if they already exist */
drop table if exists Movie;
drop table if exists Reviewer;
drop table if exists Rating;

/* Create the schema for our tables */
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);

/* Populate the tables with our data */
insert into Movie values(101, 'Gone with the Wind', 1939, 'Victor Fleming');
insert into Movie values(102, 'Star Wars', 1977, 'George Lucas');
insert into Movie values(103, 'The Sound of Music', 1965, 'Robert Wise');
insert into Movie values(104, 'E.T.', 1982, 'Steven Spielberg');
insert into Movie values(105, 'Titanic', 1997, 'James Cameron');
insert into Movie values(106, 'Snow White', 1937, null);
insert into Movie values(107, 'Avatar', 2009, 'James Cameron');
insert into Movie values(108, 'Raiders of the Lost Ark', 1981, 'Steven Spielberg');

insert into Reviewer values(201, 'Sarah Martinez');
insert into Reviewer values(202, 'Daniel Lewis');
insert into Reviewer values(203, 'Brittany Harris');
insert into Reviewer values(204, 'Mike Anderson');
insert into Reviewer values(205, 'Chris Jackson');
insert into Reviewer values(206, 'Elizabeth Thomas');
insert into Reviewer values(207, 'James Cameron');
insert into Reviewer values(208, 'Ashley White');

insert into Rating values(201, 101, 2, '2011-01-22');
insert into Rating values(201, 101, 4, '2011-01-27');
insert into Rating values(202, 106, 4, null);
insert into Rating values(203, 103, 2, '2011-01-20');
insert into Rating values(203, 108, 4, '2011-01-12');
insert into Rating values(203, 108, 2, '2011-01-30');
insert into Rating values(204, 101, 3, '2011-01-09');
insert into Rating values(205, 103, 3, '2011-01-27');
insert into Rating values(205, 104, 2, '2011-01-22');
insert into Rating values(205, 108, 4, null);
insert into Rating values(206, 107, 3, '2011-01-15');
insert into Rating values(206, 106, 5, '2011-01-19');
insert into Rating values(207, 107, 5, '2011-01-20');
insert into Rating values(208, 104, 3, '2011-01-02');

I have another relatively similar question like this, but if I get some help on this one I should be able to apply the patterns and techniques from this one to the next one.

Thanks in advance! 🙂

  • 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-05-31T10:47:51+00:00Added an answer on May 31, 2026 at 10:47 am

    I have added an inner join with derived table that returns maximum stars per movie. Because of inner join between movies and ratings only movies with ratings will be retrieved. Join it back to main query to get maximum stars per movie.

    Note: you stated that you wish to order by movie title but your query orders by reviewer.

    SELECT reviewer.name, movie.title, rating.stars, maxStarsPerMovie.MaxStars
    FROM (reviewer JOIN rating ON reviewer.rid = rating.rid)  
    JOIN movie ON movie.mid = rating.mid  
    join
    (
       select movie.mid, max(rating.stars) MaxStars
       from movie
       inner join rating
          on movie.mid = rating.mid
       group by movie.mid
    ) maxStarsPerMovie
    on movie.mid = maxStarsPerMovie.mid
    ORDER BY reviewer.name DESC
    

    EDIT: requiremets changed. This query will return list of reviewers who changed their opinion at later date in favor of the movie. It does so by joining ratings for the second time adding two filters on stars and date to join.

    SELECT reviewer.name, movie.title, rating.ratingDate, rating.stars,
           newRating.ratingDate newRatingDate, newRating.Stars newRatingStars
    FROM (reviewer JOIN rating ON reviewer.rid = rating.rid)  
    JOIN movie ON movie.mid = rating.mid 
    inner join rating newRating
         on newRating.mid = movie.mid
            and newRating.rid = reviewer.rid
            and newRating.ratingdate > rating.ratingdate
            and newRating.stars > rating.stars
    ORDER BY reviewer.name, movie.title
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

NOTE: I have updated this since originally asking the question to reflect some of
Note : The code in this question is part of deSleeper if you want
Note: I accidentally posted this question without specifying which STL implementation I was using,
Note: This question was originally part of Magento SOAP API V2 with C#: Issue
Note: Originally this question was asked for PostgreSQL, however, the answer applies to almost
(Note: This is for MySQL's SQL, not SQL Server.) I have a database column
Here's part of my Note class: class Note attr_accessor :semitones, :letter, :accidental def initialize(semitones,
Note: I've read this and its not quite what I'm looking for: I have
note: question title is change as discussed in this meta Q&A I'm using the
(Note: the data here is a made up example since I can't post the

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.