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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:59:31+00:00 2026-05-25T00:59:31+00:00

I have this table named events in my mysql database: +—–+———–+——————————+————+ | ID |

  • 0

I have this table named “events” in my mysql database:

+-----+-----------+------------------------------+------------+
| ID  | CATEGORY  | NAME                         | TYPE       |
+-----+-----------+------------------------------+------------+
| 1   | 1         | Concert                      | music      |
| 2   | 2         | Basketball match             | indoors    |
| 3   | 1         | Theather play                | outdoors   |
| 4   | 1         | Concert                      | outdoors   |
+-----+-----------+------------------------------+------------+

I need a query to count the events with category 1 and which type is music and also outdoors
Meaning that from the table above the count should be only 1: there are three events with category 1
but only “Concert” has type outdoor and music (ID 1 and ID 4).

What would be that query? Can that be done?

  • 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-25T00:59:31+00:00Added an answer on May 25, 2026 at 12:59 am

    Try this:

    SELECT count(DISTINCT e1.name)
    FROM `events` AS e1
    JOIN `events` AS e2 ON e1.name = e2.name
    WHERE e1.category = 1 
        AND e2.category = 1 
        AND e1.type = 'music' 
        AND e2.type = 'outdoor'
    

    Or a harder to understand way, but way faster than the previous one:

    SELECT count(*) FROM (
        SELECT `name`
        FROM `events`
        WHERE `category` = 1
        GROUP BY `name`
        HAVING SUM( `type` = 'music') * SUM( `type` = 'outdoor' ) >= 1
    ) AS notNeeded
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this POJO mapped to my MySQL database: @Entity @Table(name = participantespresentes, catalog
I have a table in my MySQL database called Sponsors . This table has
I have a table named Info of this schema: int objectId; int time; int
I have a table named visiting that looks like this: id | visitor_id |
I have this class called Table: class Table { public string Name { get
If I have a table like this: CREATE TABLE sizes ( name ENUM('small', 'medium',
I have a DataGridView binded to this table: [Users] ID Name -- ---- 11
I have this XML in a column in my table: <keywords> <keyword name=First Name
Let's say I have a table like this: name | score_a | score_b -----+---------+--------
I have a MySQL table containing event data. On this table, I have a

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.