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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:07:34+00:00 2026-05-20T20:07:34+00:00

Can anybody help me with this query ? I have 3 tables : orders,

  • 0

Can anybody help me with this query ?

I have 3 tables : orders, customers and products.

I need to have a list of the number of orders for each customer + for each product.
Like this:

Customer A    Product X     4
Customer A    Product Y     0
Customer A    Product Z     0
Customer B    Product X     2
Customer B    Product Y     0
Customer B    Product Z     1
Customer C    Product X     0
Customer C    Product Y     0
Customer C    Product Z     8

I tried a query like this :

SELECT c.Name, p.Name, COUNT(o.OrderID)
FROM orders AS o
RIGHT JOIN customers AS c ON c.CustomerID=o.CustomerID
RIGHT JOIN products AS p ON p.ProductID=o.ProductID
GROUP BY c.Name, p.Name

but I can’t get it to work !
It only displays the combinations where the counter>0 (where there are records in ‘orders’). But with only 1 join it DOES work, and then it DOES correctly display the records with a counter of 0. (In this example there are no products Y sold, but I do want to see Y in the list of combinations)

Any ideas?

  • 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-20T20:07:35+00:00Added an answer on May 20, 2026 at 8:07 pm

    Use a cross join. This is Oracle SQL, so not sure if it’ll work for mysql.

    select c.Name, p.Name, count(o.orderid)
    from customers c cross join products p
    left join orders o on c.customerid=o.CustomerID and p.ProductID=o.ProductID
    GROUP BY c.Name, p.Name
    order by c.name, p.name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anybody help me to build an XSD file to validate XMLs like these:
Can anybody help me out to know the possible reasons for which Apple store
I would be extremely appreciative if anybody can help me. I am learning C++
My goal is to get a query written. I have three tables, A, B
Okay, so I have this problem with my Fact Table. I need it to
Could anybody help with this? I am trying to integrate a coupon function into
I have found this example on StackOverflow: var people = new List<Person> { new
If all tables I want to delete from have the column gamer_id can i
I have this query: SELECT a.id, b.discount FROM (a LEFT JOIN b ON b.id_a
hey friends, i have been assigned a query planning project. in this project if

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.