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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:54:55+00:00 2026-05-27T15:54:55+00:00

Question resolved I have two tables, orders and customers, and I’d like to find

  • 0

Question resolved

I have two tables, orders and customers, and I’d like to find all customers where orders is greater than 0.

I currently use two queries:

SELECT * FROM customers 

and

SELECT count(id) 
FROM orders 
WHERE customer='CUSTOMER_VALUE' 
AND siteid='siteid'

I’d like to turn this into one query, so it finds all customers where they’ve placed one or more orders in the store.

I tried the following, but it doesn’t work:

SELECT c.*, 
       COUNT(o.customer) AS numOrders 
FROM customers c, 
     orders o 
WHERE o.siteid= 'calico' 
AND o.customer=c.email

(it only gives one result, which is customer ID 1).

I only need to find the orders value, and a few values from the customers table.

The customer field in orders and the id field in customers are the same value (ie order 1 was placed by customer 5, customer id 5 is “John”).

Is there any way to do this?

The current way works, but it would be greatly inefficient if there was to be a large amount of customers.

  • 1 1 Answer
  • 2 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-27T15:54:56+00:00Added an answer on May 27, 2026 at 3:54 pm

    The reason your second query is returning only 1 row, is because oyu dont have a GROUP BY. Unlike many SQL databases, MySQL does allow you to mix non-aggregated fields with aggregated ones, even though its technically not valid sql, and the results are unpredictable.

    Try

    SELECT c.id, c.email, COUNT(o.customer) AS numOrders 
     FROM customers c 
      INNER JOIN orders o on (o.customer=c.email) 
      WHERE o.siteid= 'calico' 
     GROUP BY c.id, c.email
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have asked this question ever before and it seems I didn't 100% resolved
Question about the m2 eclipse plugin. Currently I have Eclipse Java EE IDE for
I have two questions related to function objects and function pointers, Question : 1
Since I posted this question, this issue has resolved itself. There must have been
I have two database tables. One table stores data for a commitment that a
In my project I have two libraries that would currently result in a circular
Stupid nHibernate noob question, but I can't find the answer anywhere ... I have
With your help I have successfully resolved a question that I have asked here
I use git-new-workdir to have two working trees for one git repository. This usually
I have found several questions asking about template typedefs in C++0x, which are resolved

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.