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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:37:59+00:00 2026-05-26T19:37:59+00:00

I have already a query with multiple JOINs, simple list of reservations SELECT reservation.reservation_id,

  • 0

I have already a query with multiple JOINs, simple list of reservations

SELECT reservation.reservation_id, customer.customer_id, customer.name, count(ordered_services.reservation_id) AS num_of_ordered_services
FROM reservations
JOIN customers ON reservations.customer_id = customer.customer_id
LEFT JOIN ordered_services ON reservations.reservation_id = ordered_services.reservation_id
GROUP BY reservation.reservation_id, customer.customer_id, customer.name
ORDER BY reservation.reservation_id

which outputs something like

reservation_id | customer_id | name | num_of_ordered_services
     1         |  1909091202 | John |          2 
     2         |  2512541508 | Jane |          3 

I would like to add another column with information about payment, but simple JOIN, LEFT JOIN interferes with existing count() column. Like

SELECT reservation.reservation_id, count(payments.reservation_id) AS num_of_payments
FROM reservations
LEFT JOIN payments ON reservations.reservation_id = payments.reservation_id
GROUP BY reservation.reservation_id
ORDER BY reservation.reservation_id

reservation_id | num_of_payments
     1         |       0 
     2         |       2

but in both a single result. How to achieve this?

PS: num_of_payments is not necessary, I only need to know if the payment for certain reservation exists or not (1, 0).
Thank you


tbl structure, nothing special:
reservations

reservation_id | customer_id |        added
     1         |  1909091202 | 2011-11-04 02:37:28
     2         |  2512541508 | 2011-11-04 14:27:01

customers

customer_id | name | personal information columns ...
 1909091202 | John |       |      | 
 2512541508 | Jane |       |      |  
    ...     | ...  |       |      |

payments

payment_id | reservation_id | customer_id | total |        added
     1     |        2       |  1909091202 |   199 | 2011-11-04 02:37:28
     2     |        2       |  2512541508 |    50 | 2011-11-04 14:27:01
  • 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-26T19:38:00+00:00Added an answer on May 26, 2026 at 7:38 pm

    You could use a subselect for the additional field.

    SELECT reservation.reservation_id, customer.customer_id, customer.name, 
    count(ordered_services.reservation_id) AS num_of_ordered_services,
    (SELECT count(*) FROM payments WHERE reservation.reservation_id=payments.reservation_id) AS num_of_payments
    FROM reservations
    JOIN customers ON reservations.customer_id = customer.customer_id
    LEFT JOIN ordered_services ON reservations.reservation_id = ordered_services.reservation_id
    GROUP BY reservation.reservation_id, customer.customer_id, customer.name
    ORDER BY reservation.reservation_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does COUNT(*) have any significant impact for MySQL performance if query already has GROUP
I have a simple query: select * from countries with the following results: country_name
I am not asking for the simple select query. I have a detailed table
I have already tried multiple ways. defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions '{ORGANIZATIONNAME=YourNameHere;}' Also i've tried
I have a SQL query where I want to insert multiple rows in single
I am wanting to produce a query which allows me to select multiple records
So I have a checkbox form where users can select multiple values. Then can
I have already pushed all the changes to the server. Here is the order
I have already download and install this package to support HTML5 input type http://support.microsoft.com/kb/2468871
I have already googled and searched stackoverflow but I can find nothing related to

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.