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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:33:39+00:00 2026-06-07T20:33:39+00:00

I have an orders table that stores orders from multiple sites within our company.

  • 0

I have an orders table that stores orders from multiple sites within our company. In the table we have the fields userid, ordernumber and sitename. What I’d like to be able to get is the number of users who have orded from 2 or more of our sites.

This is what I started with:

SELECT
  o.ordernumber,
  o.sitename,
  o.userdbid,
  o2.sitename,
  o2.userdbid,
  o2.ordernumber
FROM
  orders o
INNER JOIN
  orders o2
ON
  o.userdbid = o2.userdbid
WHERE
  o.sitename != o2.sitename
ORDER BY
  o.userdbid;

This isn’t close to correct but this as close as I could think to get. Any help or direction would be very much appreciated.

  • 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-06-07T20:33:41+00:00Added an answer on June 7, 2026 at 8:33 pm

    You will need a HAVING clause to compare the aggregate COUNT() to 2, wherein you have grouped by userbid. Be sure to use DISTINCT in your aggregate COUNT() so that you get multiple sites rather than just multiple orders.

    SELECT
      o.userbid,
      COUNT(DISTINCT o.sitename) AS num_order_sites
    FROM
      orders o
    GROUP BY o.userbid
    HAVING COUNT(DISTINCT o.sitename) >= 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ecommerce MySQL database that stores order information in the table 'orders'
If I have a table Orders with fields CustomerID , OrderID and OrderDate ,
I have a table with a collection of orders. The fields are: customerName (text)
I have a SQL Server table full of orders that my program needs to
I have a SQL Server 2005 database that stores data for multiple users. Each
I have a table called faq . This table consists from fields faq_id ,
I have a table that looks like: Client_ID | Order_ID | 10 | 1
Lets say that I have three tables, customers, orders and orderDetails. I'm doing this:
I have an orders table with a schema like this. CREATE TABLE orders (
Suppose I have an Orders table in my database and a corresponding model class

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.