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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:58:52+00:00 2026-05-22T14:58:52+00:00

This is a SQL question involving a join giving me more than I want.

  • 0

This is a SQL question involving a join giving me more than I want.

I have 2 tables, an events table and singers table

EVENTS
event_id
event_name
num_attendees
tickets_sold
tickets_promo
event_date
... many other fields
SINGERS
event_id
singer

I’m trying to get event statistics from the events table if ANY of a list of singers performed.

EVENTS:
event_id num_attendees tickets_sold
   1        15              2500
   2         5              1575

Singers at the event:
event_id  singer
   1      bob
   1      jane
   2      bob

I’m interested in the statistics of events that either bob or jane sang in:

SELECT count(e.event_id) as count_events, sum(num_attendees) as sum_attentees, 
       sum(tickets_sold) as sum_tickets_sold
  FROM `events` e
       INNER JOIN singers s ON s.event_id = e.event_id 
   AND s.singer IN ("bob", "jane")
 WHERE event_date ...

Gives me a wrong count and sums since the join will give me 2 records for event 1, and 1 record for event 2 and the count of events will be 3.

How should I write this SQL? 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-22T14:58:53+00:00Added an answer on May 22, 2026 at 2:58 pm
    SELECT count(e.event_id) as count_events,
           sum(num_attendees) as sum_attentees,
           sum(tickets_sold) as sum_tickets_sold 
    FROM events e 
    WHERE e.event_id IN 
         (SELECT DISTINCT event_id FROM singers WHERE singer IN ("bob", "jane"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a similar question to this one SQL products/productsales I want to do
This is a SQL design question. First, the setup. I have three tables: A,
This is a SQL query question. If you have a table like this: ID1
This is a sql newbie question. Basically, I want an extra column to return
This is sort of SQL newbie question, I think, but here goes. I have
I recently asked this question: MS SQL share identity seed amongst tables (Many people
EDIT: Let me turn this into a straight SQL question... I have a varbinary(max)
This looks like a noob T-SQL question but I want do switch like logic
This question os partially a Drupal question and partially a SQL question. I have
I have dropped on this question: SQL query to find Missing sequence numbers .

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.