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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:26:12+00:00 2026-05-17T23:26:12+00:00

Alright, I’m trying to link three different tables (Customers, Orders, and Order Details), in

  • 0

Alright, I’m trying to link three different tables (Customers, Orders, and Order Details), in an effort to figure out which customers ordered the same item twice. I’m stumped. Here’s what I’ve come up with thus far:

Select ContactName, Orders.OrderID, ProductID From Customers
inner join Orders on Customers.CustomerID = Orders.CustomerID
join [Order Details] on [Order Details].OrderID = Orders.OrderID;

I was thinking it’d be easiest to find ProductIDs that have the correlating ContactName but a different Orders.OrderID… and this is what I’m having trouble with. Any help would be 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-05-17T23:26:13+00:00Added an answer on May 17, 2026 at 11:26 pm

    you need to select two different orders which have a detail with the same product. (“select all customers which have two different orders with the same product”)

    Select 
      ContactName, 
      o1.OrderID, 
      o2.OrderID, 
      od1.ProductID 
    From 
      Customers
      inner join Orders o1 on Customers.CustomerID = o1.CustomerID
      join [Order Details] od1 on od.OrderID = o1.OrderID;
      inner join Orders o2 on Customers.CustomerID = o2.CustomerID
      join [Order Details] od2 on od.OrderID = o2.OrderID;
    where 
      o1.orderid <> o2.orderid
      and od1.productid = od2.productid
    

    or use a subquery. (“select all customers which have a product detail with the same product as in another order of the same customer”);

    Select 
      ContactName, 
      o1.OrderID, 
      od1.ProductID 
    From 
      Customers
      inner join Orders o1 on Customers.CustomerID = o1.CustomerID
      join [Order Details] od1 on od.OrderID = o1.OrderID;
    where 
      od1.productid IN
        (SELECT od2.productid 
        FROM
          Orders o2 on Customers.CustomerID = o2.CustomerID
          join [Order Details] od2 on od.OrderID = o2.OrderID
        where 
          o1.orderid <> o2.orderid)
    

    Or use group by. then you can count them. You can aggregate different values, for instance the total amount ordered or the total prize payed.

    Select 
      ContactName, 
      od1.ProductID
      count(*) as "number of repeated orders details",
      count(distinct o1.orderid) as "number of different orders"
    From 
      Customers
      inner join Orders o1 on Customers.CustomerID = o1.CustomerID
      inner join [Order Details] od1 on od.OrderID = o1.OrderID;
    group by 
      ContactName, 
      od1.productId
    having 
      count(distinct o1.orderid) > 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright, I'm trying to figure out why I can't understand how to do this
Alright so my program is getting the user's input to figure out the prime
Alright, this one's got me seriously stumped, after trying things out for hours with
Alright, here I am again trying to write code from scratch and I can't
Alright i have a table which contains 2 bigint column. Example val1 3213 12312
Alright, so I've done a bit of searching and trying with no luck. I'm
Alright, I recently wrote a ajax push script which had php on the backend
Alright, so I wrote a custom VMR9 Allocator/Presenter which seems to work fine. However,
Alright, so I've successfully added a custom order field to my page layout in
Alright I have the MYSQL query code setup to pull this information out of

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.