List:General Discussion« Previous MessageNext Message »
From:John Nichel Date:July 12 2012 5:49pm
Subject:Finding Rows With Common Items
View as plain text  
Hi all,

Lets say I have a table with two colums: 'orderid' and 'productid'.  This
table contains line items for purchases in a store where a purchase could
be 1 or more line items (1 or more rows).  A typical order may look like

orderid | productid
12345   | 9876
12345   | 6789
12345   | 7698

Is there a simple way to query the table to pull orders which have 2 or
more products in common?  For example, if order 12345 has 5 line items and
order 12348 has 7 line items, I would like the query to return these two
orders if they have products 9876 and 6789 in common, and I would also
like it to return orders 23456, 65432 and 34567 where they have 8796, 6789
and 4456 in common.  I hope I'm explaining this well...I know what I'm
trying to accomplish in my head, but we all know that doesn't always
translate too well in an email.  :)  For the record, this is a MySQL
4.1.22 db.  TIA

John C. Nichel IV
System Administrator
716.362.9212 x160
Finding Rows With Common ItemsJohn Nichel12 Jul
  • Re: Finding Rows With Common ItemsShawn Green12 Jul
    • Re: Finding Rows With Common ItemsAnanda Kumar12 Jul