3

I'm trying to find out which orders have been made more than once. This will help me identify the most common orders. Here is my orders table with some dummy data;

Table name: Orders

OrderID | ProductID | Quantity -------- | ----------| -------- 1 | 3 | 6 | 1 | 6 | 3 | 2 | 5 | 1 | 3 | 10 | 9 | 3 | 9 | 1 | 3 | 3 | 2 | 4 | 6 | 3 | 4 | 3 | 6 |

As you can see orders 1 and 4 are the same order I need a query to help me identify these orders.

JBull
  • 43
  • 1
  • 8

2 Answers2

0

You can use a group by and having like this

SELECT OrderID, ProductID, Quantity, Count(*) as Count
FROM Your_table_name_which_you_did_not_tell_us
GROUP BY OrderID, ProductID, Quantity
HAVING COUNT(*) > 1
Hogan
  • 69,564
  • 10
  • 76
  • 117
0

FYI this did the job for me;

"SELECT MIN(orderID) as orderId, COUNT(*) as TimesOrdered" + " FROM ORDERS" + " GROUP BY partId, quantity" + " HAVING COUNT(*)>1";

JBull
  • 43
  • 1
  • 8