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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:54:41+00:00 2026-05-16T09:54:41+00:00

I have a system where reservations are stored as records in one table(workshop_reservation) and

  • 0

I have a system where reservations are stored as records in one table(workshop_reservation) and sessions (the things being reserved) are stored in another table(session). Each reservation belongs to a session, and each session belongs to a workshop.

I want to make a mysql query that finds the number of reservations for each session that belongs to a certain workshop. I was trying to use count() to find the number of reservations in a given session, and this query works fine for that purpose (# is the session number):

SELECT count( r.id )
FROM workshop_reservation AS `r`
WHERE r.session_id = #

I want to figure out how to perform this query for every session. I can easily find every session_id using the following query:

SELECT s.id
FROM session AS `s` 

My problem is combining these, because when any of the sessions have no reservations, no row is printed for that session. Instead, I want it to print a 0 in the count column for sessions that have no reservations. The following query works fine for sessions that have at least one reservation, but it ignores sessions that have no reservations (doesn’t print a row saying 0).

SELECT count( r.id ) , r.session_id
FROM workshop_reservation AS `r`
WHERE r.session_id
IN (
SELECT s.id
FROM session AS `s`
WHERE s.workshop_id =1
)
AND r.reservation_status_id =0
GROUP BY r.session_id

How can I force it to print a row with a 0 in it in this situation?

  • 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-16T09:54:41+00:00Added an answer on May 16, 2026 at 9:54 am

    I thought I should put this here instead of choosing one of your answers, since neither of them quite worked alone. I used elements from both (mostly mdma with one line from nico). Here is the query that does exactly what I want:

    SELECT session.id, count( workshop_reservation.id )
    FROM session LEFT JOIN workshop_reservation ON session.id = workshop_reservation.session_id
    AND workshop_reservation.reservation_status_id =0
    GROUP BY session.id
    

    I don’t know how obvious this is to SQL experts, but if the AND is changed to WHERE, the reservation_status_id is actually ignored.

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

Sidebar

Related Questions

I am trying to make a simple reservation system. I have a table called
I'm making a reservation system with one row per reservation in a mySql table.
I have made a booking system for online ticket reservations, but they cant pay
Iam working on small booking room system. In my solution I have a Reservation
We have system here that uses Java JNI to call a function in a
I have System.Collections.Generic.Dictionary<A, B> dict where A and B are classes, and an instance
Let's say we have system A comprising a MySQL database, with several tables. After
I have a system with 4 Physical Processor sockets. Running Windows 2003, I would
I have a system that takes dynamic data, puts it in HTML for layout
I have a System.Windows.Forms.ComboBox on a form and I want to capture the event

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.