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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:15:41+00:00 2026-05-14T03:15:41+00:00

I received some great help on joining a table to itself and am trying

  • 0

I received some great help on joining a table to itself and am trying to take it to the next level. The SQL below is from the help but with my addition of the select line beginning with COUNT, the inner join to the Recipient table, and the Group By.

SELECT
  Event.EventID              AS EventID,
  Event.EventDate            AS EventDateUTC,
  Participant2.ParticipantID AS AwayID,
  Participant1.ParticipantID AS HostID,
  COUNT(Recipient.ChallengeID) AS AllChallenges
FROM Event
  INNER JOIN Matchup Matchup1
    ON (Event.EventID = Matchup1.EventID)
  INNER JOIN Matchup Matchup2
    ON (Event.EventID = Matchup2.EventID)
  INNER JOIN Participant Participant1
    ON (Matchup1.Host = 1
        AND Matchup1.ParticipantID = Participant1.ParticipantID)
  INNER JOIN Participant Participant2
    ON (Matchup2.Host != 1
        AND Matchup2.ParticipantID = Participant2.ParticipantID)
  INNER JOIN Recipient
    ON (Event.EventID = Recipient.EventID)
WHERE Event.CategoryID = 1
    AND Event.Resolved = 0
    AND Event.Type = 1
GROUP BY Recipient.ChallengeID
ORDER BY EventDateUTC ASC

My goal is to get a count of how many rows in the Recipient table match the EventID in Event. This code works fine except that I also want to get results where there are 0 matching rows in Recipient. I want 15 rows (= the number of events) but I get 2 rows, one with a count of 1 and one with a count of 2 (which is appropriate for an inner join as there are 3 rows in the sample Recipient table, one for one EventID and two for another EventID).

I thought that either a LEFT join or an OUTER join was what I was looking for, but I know that I’m not quite getting how the tables are actually joined. A LEFT join there gives me one more row with 0, which happens to be EventID 1 (first thing in the table), but that’s all. Errors advise me that I can’t just change that INNER join to an OUTER. I tried some parenthesizing and some subselects and such but can’t seem to make it work.

  • 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-14T03:15:41+00:00Added an answer on May 14, 2026 at 3:15 am

    Use:

       SELECT e.eventid,
              e.eventdate AS EventDateUTC,
              p2.participantid AS AwayID,
              p1.participantid AS HostID,
              COUNT(r.challengeid) AS AllChallenges
         FROM EVENT e
         JOIN Matchup m1 ON m1.eventid = e.eventid
                        AND m1.host = 1
         JOIN Matchup m2 ON m2.eventid = e.eventid
                        AND m2.host != 1
         JOIN Participant p1 ON p1.participantid = m1.participantid
         JOIN Participant p2 ON p2.participantid = m2.participantid
    LEFT JOIN RECIPIENT r ON r.eventid = e.eventid
        WHERE e.categoryid = 1
          AND e.resolved = 0
          AND e.type = 1
     GROUP BY e.eventid, e.eventdate, p2.participantid, p1.participantid
     ORDER BY e.eventdate
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have received some JavaScript from an agency that looks wrong, but works. For
I'm back with another Flex/Flash security question. I've already received some help from the
I received some great help here the other day and hope once again I
I just received some really great help today with a prior jQuery problem and
Flawed as I am, I've received some unneeded help in creating errors in the
Thanks to some help I received yesterday I've got some dynamic summing working on
I received the error while trying to display some variable like so: echo id
I received some xml data that includes a timestamp taken at midnight of the
I received some multi-line data via HTTP and have it in one string. I
We're developing a pretty large application with MVC 2 RC2 and we've received some

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.