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 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

I am attempting to get some information from a website, the info that I
I am attempting to get some information from a russian shipping website. Being a
This code is used to get a specific list of ID's from one table,
I am attempting to get information from an HTML form to a PHP script.
I'm attempting to get the information from the brews and recipes tables based off
Im attempting to get a block of text from a file I have already
I am attempting to get a count of items in an array to place
I'm attempting to get order data from a Yahoo store. I'm using the docs
I am attempting to get a distinct list of id's back that would be
I have 2 mysql statements one gets all the information from 4 linked tables

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.