user1895076 user1895076 - 1 year ago 103
SQL Question

Oracle SQL - Comparing Rows

I have a problem I'm working on with Oracle SQL that goes something like this.


PurchaseID CustID Location

I'm interested in querying the Table to return all instances where the same customer makes a purchase in different locations. So, for the table above, I would want:


PurchaseID CustID Location

Any ideas on how to accomplish this? I haven't been able to think of how to do it, and most of my ideas seem like they would be pretty clunky. The database I'm using has 1MM+ records, so I don't want it to run too slowly.

Any help would be appreciated. Thanks!

Answer Source
FROM YourTable T
                 FROM YourTable
                 GROUP BY CustId
                 HAVING MIN(Location) <> MAX(Location))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download