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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:57:10+00:00 2026-06-13T01:57:10+00:00

I have this SQL Server query which I wrote to find the Movie title

  • 0

I have this SQL Server query which I wrote to find the Movie title that has the least amount of records in the RENTAL table.

When run, it returns a resultset that is identical to the resultset I get from executing the sub-query by itself.

In other words, rather returning the single movie with the minimum RentalCount, it returns all movie titles and their corresponding RentalCount.

SELECT B.Title, MIN(B.RentalCount) AS RentalCount
FROM (
    SELECT Movie.Title, Count(*) AS RentalCount
    FROM Rental
    JOIN Dvd ON Rental.RentalID=Dvd.DvdID
    JOIN Movie ON Dvd.Movieid=movie.MovieID
    GROUP BY Movie.Title
    ) B
GROUP BY B.Title
  • 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-13T01:57:11+00:00Added an answer on June 13, 2026 at 1:57 am

    The result is correct. Your subquery returns the total count for each title on the rental table. And the result will be the same on the outer query because you have grouped them by their title also.

    follow-up question: what result do you want to achieved?

    find the Movie title that has the least amount of records in the RENTAL table

    SELECT Movie.Title, Count(*) AS RentalCount
    FROM Rental
            JOIN Dvd ON Rental.RentalID=Dvd.DvdID
            JOIN Movie ON Dvd.Movieid=movie.MovieID
    GROUP BY Movie.Title
    HAVING Count(*) = 
        (
            SELECT MIN(t_count)
            FROM
            (
                SELECT Count(*) t_count
                FROM Rental
                GROUP BY Title
            ) a
        )
    

    UPDATE 1

    Thanks to Martin Smith for introducing me TOP....WITH TIES

    SELECT TOP 1 WITH TIES Movie.Title, Count(*) AS RentalCount
    FROM Rental
            JOIN Dvd ON Rental.RentalID=Dvd.DvdID
            JOIN Movie ON Dvd.Movieid=movie.MovieID
    GROUP BY Movie.Title
    ORDER BY RentalCount DESC
    

    SQLFiddle Demo

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this question in which I have a SQL Server Compact Edition database
I currently have this statement in my SQL View (SQL Server 2008 R2) which
I have written a MDX query which works fine in SQL Server Management Studio.
In SQL Server 7.0, I need to find out which users have write access
I have a SQL Server 2005 database which has about 30-40 connections to the
I wrote a query that works like a charm in SQL Server. Unfortunately it
I have this table structure on a SQL Server 2008 R2 database: CREATE TABLE
In Microsoft SQL Server: I have seen this question several times, but can't see
This is SQL Server 2008. I have these two tables and a join: DECLARE
I have a table like this in SQL Server: varID(PK) dataID(PK) is_used A 1

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.