# Thread: How to retrieve unique rows based on column value combinations?

1. Registered User
Join Date
Jan 2016
Posts
2

## Unanswered: How to retrieve unique rows based on column value combinations?

I have a table mytable like below;

Code:
╔═════════╦═════╦═════╗
║ product ║ tag ║ lot ║
╠═════════╬═════╬═════╣
║ 1111    ║ 101 ║ 2   ║
║ 1111    ║ 102 ║ 5   ║
║ 2222    ║ 103 ║ 6   ║
║ 3333    ║ 104 ║ 2   ║
║ 4444    ║ 101 ║ 2   ║
║ 5555    ║ 101 ║ 2   ║
║ 5555    ║ 102 ║ 5   ║
║ 6666    ║ 102 ║ 2   ║
║ 6666    ║ 103 ║ 5   ║
║ 7777    ║ 101 ║ 2   ║
║ 7777    ║ 102 ║ 5   ║
║ 7777    ║ 103 ║ 6   ║
║ 8888    ║ 101 ║ 1   ║
║ 8888    ║ 102 ║ 3   ║
║ 8888    ║ 103 ║ 5   ║
║ 9999    ║ 101 ║ 6   ║
║ 9999    ║ 102 ║ 8   ║
╚═════════╩═════╩═════╝
I have the input 101,102. I want the output like;

2,5
6,8

which means, in the table, it will look for combinations 101,102, and returns the exact same combinations with different lot number. Along with this, I want to avoid duplicate rows. Here 1111 and 5555 has same tags with same corresponding lot numbers to tags, so I want only one row instead of 2 rows. Even though, 8888 has tags 101 and 102 with different lots, it cannot be considered for listing , since it includes tag 103 in addition. In short, I want products with exact 101, 102 combination, and I dont want products with any extra tags, and i dont want products with any missing tags.

How can I achieve this?

2. Registered User
Join Date
Jan 2016
Posts
2

## How to retrieve unique rows based on column value combinations?

I have a table mytable like below;

Code:
╔═════════╦═════╦═════╗
║ product ║ tag ║ lot ║
╠═════════╬═════╬═════╣
║ 1111    ║ 101 ║ 2   ║
║ 1111    ║ 102 ║ 5   ║
║ 2222    ║ 103 ║ 6   ║
║ 3333    ║ 104 ║ 2   ║
║ 4444    ║ 101 ║ 2   ║
║ 5555    ║ 101 ║ 2   ║
║ 5555    ║ 102 ║ 5   ║
║ 6666    ║ 102 ║ 2   ║
║ 6666    ║ 103 ║ 5   ║
║ 7777    ║ 101 ║ 2   ║
║ 7777    ║ 102 ║ 5   ║
║ 7777    ║ 103 ║ 6   ║
║ 8888    ║ 101 ║ 1   ║
║ 8888    ║ 102 ║ 3   ║
║ 8888    ║ 103 ║ 5   ║
║ 9999    ║ 101 ║ 6   ║
║ 9999    ║ 102 ║ 8   ║
╚═════════╩═════╩═════╝
I have the input 101,102. I want the output like;

2,5
6,8

which means, in the table, it will look for combinations 101,102, and returns the exact same combinations with different lot number. Along with this, I want to avoid duplicate rows. Here 1111 and 5555 has same tags with same corresponding lot numbers to tags, so I want only one row instead of 2 rows. Even though, 8888 has tags 101 and 102 with different lots, it cannot be considered for listing , since it includes tag 103 in addition. In short, I want products with exact 101, 102 combination, and I dont want products with any extra tags, and i dont want products with any missing tags.

How can I achieve this?

3. Registered User
Join Date
Dec 2007
Location
Richmond, VA
Posts
1,328