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

  • Home
  • SEARCH
  • 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 99075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:19:06+00:00 2026-05-11T00:19:06+00:00

I am attempting to get the information from one table (games) and count the

  • 0

I am attempting to get the information from one table (games) and count the entries in another table (tickets) that correspond to each entry in the first. I want each entry in the first table to be returned even if there aren’t any entries in the second. My query is as follows:

SELECT g.*, count(*)  FROM games g, tickets t  WHERE (t.game_number = g.game_number    OR NOT EXISTS (SELECT * FROM tickets t2 WHERE t2.game_number=g.game_number)) GROUP BY t.game_number; 

What am I doing wrong?

  • 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. 2026-05-11T00:19:06+00:00Added an answer on May 11, 2026 at 12:19 am

    You need to do a left-join:

    SELECT g.Game_Number, g.PutColumnsHere, count(t.Game_Number)  FROM games g LEFT JOIN tickets t ON g.Game_Number = t.Game_Number GROUP BY g.Game_Number, g.PutColumnsHere 

    Alternatively, I think this is a little clearer with a correlated subquery:

    SELECT g.Game_Number, G.PutColumnsHere,   (SELECT COUNT(*) FROM Tickets T WHERE t.Game_Number = g.Game_Number) Tickets_Count FROM Games g 

    Just make sure you check the query plan to confirm that the optimizer interprets this well.

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

Sidebar

Related Questions

From time to time I get a System.Threading.ThreadStateException when attempting to restart a thread.
I'm attempting to use Assembly.GetType(MyCompany.Class1.Class2) to dynamically get a type from a string. Assembly.GetType(MyCompany.Class1);
Attempting to print out a list of values from 2 different variables that are
I have an SSIS package that exports data from a table on a SQL
I'm attempting to get a set of list items from sharepoint via the WebService.
While attempting to get an old svn dump of a project under git control,
I'm attempting to get my first ASP.NET web page working on windows using Mono
I am attempting to get a DropDownList to AutoPostBack via an UpdatePanel when the
I get the following error when attempting to install RubyGems . I've tried Googling
When attempting to compile my C# project, I get the following error: 'C:\Documents and

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.