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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:38:50+00:00 2026-06-08T04:38:50+00:00

Question: How do you compare (< or >) the result of one column, against

  • 0

Question:

How do you compare (< or >) the result of one column, against the result of another column of two select statements?

More details:

I need to get a list only of the sold out movies. To do this, I need to check if
the number on the rented_movie_count on the first select statement is equal or greater than the number on the available_movie_count on the second select statement.

First Statement

result of the 
select MOVIE_ID, count(MOVIE_ID) as rented_movies_count
from MOVIE_QUEUE
WHERE STATUS_ID=2
group by MOVIE_ID;

Second Statement

select MOVIE_ID, count(MOVIE_ID) as available_movie_count
from dvd
group by MOVIE_ID;

I am still very new to this and I am trying to learn, even suggestions about what kind of
syntax (operators, expressions, etc) should I use will help at least point me on a a directions to do more research. 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-06-08T04:38:51+00:00Added an answer on June 8, 2026 at 4:38 am

    Given your database structure, a possible solution would be

    SELECT rented.MOVIE_ID
          ,rented_movies_count
          ,available_movie_count
      FROM (
            SELECT MOVIE_ID, count(MOVIE_ID) AS rented_movies_count
              FROM MOVIE_QUEUE
             WHERE STATUS_ID=2
            GROUP BY MOVIE_ID
           ) rented
         ,(SELECT MOVIE_ID, count(MOVIE_ID) AS available_movie_count
             FROM dvd
           GROUP BY MOVIE_ID
          ) available
     WHERE rented.movie_id = available.movie_id
       AND rented_movies_count >= available_movie_count 
    ;
    

    I’ve set up an example on http://www.sqlfiddle.com/#!4/3fc59/11 to test. But I guess that’s more or less what you’ve come up with.

    But I somewhat doubt that your database structure is really optimal!? Do you really store more than one record for a singe movie_id in the table dvd?

    Wouldn’t it be more useful to have exactly one record per movie_id in dvd along with some movie attributes and store the rental status of the dvds in movie_queue.status_id?

    If movie_queue.status_id is defined as say

    1. …available
    2. …rented

    Then your query would be much more easy:

    SELECT MOVIE_ID
          ,count(case when status_id = 1 then 1 end) AS available_movie_count
          ,count(case when status_id = 2 then 1 end) AS rented_movies_count
      FROM MOVIE_QUEUE
     GROUP BY MOVIE_ID
    HAVING count(case when status_id = 2 then 1 end) >= count(case when status_id = 1 then 1 end)
    ;
    

    See for example http://www.sqlfiddle.com/#!4/13739/1

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

Sidebar

Related Questions

I need to select the counts from two tables that share a common column
My question is similar to this one: Compare rows and get percentage However, little
This is a more specific question to follow up on [another question that I
As a result of another question I asked here I want to use a
I know you can check if all elements from one list exist in another
Okay, here's my short question: I know that === and !== operators will compare
Here's the question : I have 2 tables , one containing the base data
One desktop application needs to get some services from server. For example sending some
I have two identical strings, one in an array and one in a String
Starting point : I fill one table with data and in order to compare

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.