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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:53:43+00:00 2026-05-15T18:53:43+00:00

I have a bunch of Users, each of whom has many Posts. Schema: Users:

  • 0

I have a bunch of Users, each of whom has many Posts.
Schema:

Users: id
Posts: user_id, rating

How do I find all Users who have at least one post with a rating above, say, 10?

I’m not sure if I should use a subQuery for this, or if there’s an easier way.

Thanks!

  • 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-15T18:53:43+00:00Added an answer on May 15, 2026 at 6:53 pm

    To find all users with at least one post with a rating above 10, use:

    SELECT u.*
      FROM USERS u
     WHERE EXISTS(SELECT NULL
                    FROM POSTS p
                   WHERE p.user_id = u.id
                     AND p.rating > 10)
    

    EXISTS doesn’t care about the SELECT statement within it – you could replace NULL with 1/0, which should result in a math error for dividing by zero… But it won’t, because EXISTS is only concerned with the filteration in the WHERE clause.

    The correlation (the WHERE p.user_id = u.id) is why this is called a correlated subquery, and will only return rows from the USERS table where the id values match, in addition to the rating comparison.

    EXISTS is also faster, depending on the situation, because it returns true as soon as the criteria is met – duplicates don’t matter.

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

Sidebar

Related Questions

I have a web application which currently has a bunch of users and use
I have a bunch of Seam form pages; each has a command button that
I display a bunch of posts from users on a page. I have the
I have a bunch of users and each user can belong to multiple roles.
I have a bunch of support Cases and Users . Each Case is assigned
I have a a bunch of user controls(about 15, one for each record) in
I have a page that has a bunch of user controls on it. I
I have a bunch of Users . Since Django doesn't really let me extend
I am making a site that has a bunch of photos and under each
I have a bunch of HTML pages with a form on each page for

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.