on-internet
← Community

Return Customer ID for rows only containing 2 values

Stack Overflow ·

Trying to write Oracle SQL to return the customer ids that only contain BOTH fruits named: APPLE and PEAR , any customer that contains additional fruit in addition to apples and pears should be excluded from the results. Example Table: ID CUSTOMER_ID FRUIT 1 1001 APPLE 2 1001 ORANGE 3 1002 APPLE 4 1002 PEAR 5 1003 PEAR 6 1003 APPLE 7 1004 BANANA 8 1004 PEAR 9 1004 APPLE 10 1005 PEAR 11 1006 APPLE Ideally I need customer_ids 1002 and 1003 returned and the remainder ignored as they don't have APPLE and PEAR only. 1005 will be ignored too as it only contains PEAR same for 1006 as it only contains

Comments

Sign in or sign up to comment and upvote.

No comments yet.