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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:07:10+00:00 2026-06-04T20:07:10+00:00

The question is this.. Table is this.. +————————–+———+——+—–+———+—————-+ | Field | Type | Null

  • 0

The question is this..

Table is this..

+--------------------------+---------+------+-----+---------+----------------+
| Field                    | Type    | Null | Key | Default | Extra          |
+--------------------------+---------+------+-----+---------+----------------+
| facility_map_id          | int(10) | NO   | PRI | NULL    | auto_increment |
| facility_map_facility_id | int(10) | NO   | MUL | NULL    |                |
| facility_map_listing_id  | int(10) | NO   |     | NULL    |                |
+--------------------------+---------+------+-----+---------+----------------+

Data is this..

+-----------------+--------------------------+-------------------------+
| facility_map_id | facility_map_facility_id | facility_map_listing_id |
+-----------------+--------------------------+-------------------------+
|             248 |                        1 |                      18 |
|             259 |                        1 |                      19 |
|             206 |                        1 |                      20 |
|             244 |                        1 |                      21 |
|             249 |                        2 |                      18 |
|             207 |                        2 |                      20 |
|             208 |                        3 |                      20 |
|             245 |                        3 |                      21 |
|             260 |                        4 |                      19 |
|             261 |                        5 |                      19 |
|             246 |                        6 |                      21 |
|             250 |                        7 |                      18 |
|             247 |                        8 |                      21 |
+-----------------+--------------------------+-------------------------+

I run the this query :

SELECT facility_map_listing_id 
FROM facility_map 
WHERE facility_map_facility_id IN(1, 2) 
GROUP BY facility_map_listing_id 
HAVING count(DISTINCT facility_map_facility_id) >= 2 

and get this..

+-------------------------+
| facility_map_listing_id |
+-------------------------+
|                      18 |
|                      20 |
+-------------------------+
2 rows in set (0.00 sec)

Which is correct! – but can anyone explain, why the GROUP BY needs to be in the statement?

if it Isnt and I run the same query leaving out the GROUP BY I get..

+-------------------------+
| facility_map_listing_id |
+-------------------------+
|                      18 |
+-------------------------+
1 row in set (0.00 sec)

Can any one explain this to me? Thank you!

  • 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-04T20:07:12+00:00Added an answer on June 4, 2026 at 8:07 pm

    Without a group by, an aggregate like count works on the set as a whole. So this query returns either zero or one row:

    SELECT facility_map_listing_id 
    FROM facility_map 
    WHERE facility_map_facility_id IN(1, 2)
    HAVING count(DISTINCT facility_map_facility_id) >= 2 
    

    It will return one row if the having condition is met, and an empty set otherwise.

    Now, with the group by, it evaluates the having condition for each value of facility_map_listing_id. That can return up to as many rows as there are distinct values of facility_map_listing_id.

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

Sidebar

Related Questions

Based on this previous question on stackoverflow: Fetch Oracle table type from stored procedure
This question is about Postgresql 8.3 . I've got a table with a field
For the sake of this question, let's suppose this table structure: People: PersonID int
I am asking this question because if a table has a key that consists
I have (simplified for this question) a table 'TAB' with two columns 'id' (integer
This question is similar to GWT Table that supports sorting, scrolling and filtering However
This question is along the lines of HTML table horizontal spacing We have an
This question does pretty much what I want to accomplish, but my table is
this time i have a simple question: I have one table, related with himself
This is more like a question of principle. I made a table with 100%

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.