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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:52:48+00:00 2026-05-26T17:52:48+00:00

Consider the following data structure: parking garages | |_ garage 1 |__ red car

  • 0

Consider the following data structure:

parking garages
    |
    |_ garage 1
        |__ red car
        |__ blue car
    |_ garage 2
        |__ yellow car
        |__ orange car
    |_ garage 3
        |__ red car
        |__ red car
        |__ yellow car

“parking garages” is a table, and each entry is a foreign key to a “garageCars” table containing one record for each car in the garage.

What I would like to do is write a query that would return “garage 3” because it has 2 red cars

I’ve tried using the HAVING clause with a count, but this returns all the rows that have more than 1 car. I need something more along the lines of “WHERE count(car) > 1 and car.color = car.color”.

  • 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-26T17:52:48+00:00Added an answer on May 26, 2026 at 5:52 pm

    Assuming you only want the garage name and not the color that’s duped because you want “… query that would return “garage 3″ because it has 2 red cars”

    Using a Derived Table

    SELECT g.garagename 
    FROM   garage g 
           INNER JOIN (SELECT garage_id 
                       FROM   cars 
                       GROUP  BY garage_id, 
                                 carcolor 
                       HAVING COUNT(garage_id) > 1) c 
             ON g.garage_id = c.garage_id 
    

    Using IN

    SELECT g.garagename 
    FROM   garage g 
    WHERE  g.garage_id IN (SELECT garage_id 
                           FROM   cars 
                           GROUP  BY garage_id, 
                                     carcolor 
                           HAVING COUNT(garage_id) > 1) 
    

    You could also do it with EXISTS, CROSS APPLY or with a CTE

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

Sidebar

Related Questions

Consider the following data structure: List<Person> People; class Person { List<Car> Cars; List<Hobby> Hobbies;
Consider the following data model: Suppose I have a table called SuperAwesomeData where each
Consider the following table structure with data - AdjusterID | CompanyID | FirstName |
For my question lets consider the following sample table data: ProductID    ProductName    Price   Category 1                Apple                 5.00       Fruits
Please consider the following table structure on Oracle: create table DOCS ( DOC_NO NUMBER
Consider the following table structure: titles(titleID*, titleName) platforms(platformID*, platformName) products(platformID*, titleID*, releaseDate) publishers(publisherID*, publisherName)
Consider the following table structure (not designed by me, and unchangable): +---------------+-----------------------------+---------------------------+ | the_id
Consider the following table. It has 3 filed with the following data. Now I
Consider this scenario: I've an XML file called person.xml with the following data in
Consider the following two FFI structs: class A < FFI::Struct layout :data, :int end

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.