5

I have a table mytable like below;

╔═════════╦══════╦═════╗
║ 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

I have a query like;

select group_concat(lot order by lot)
from `mytable`
group by product
having group_concat(tag order by tag) = '101,102';

It returns;

2,5
2,5
6,8

Instead of two 2,5, I want just one, avoiding duplicate rows. How can I do this?

Here is the fiddle http://sqlfiddle.com/#!9/7a78bb/1/0

4

2 Answers 2

7

If you want distinct then

select distinct group_concat(lot order by lot)
from `mytable`
group by product
having group_concat(tag order by tag) = '101,102';
Sign up to request clarification or add additional context in comments.

Comments

0

You need to just use DISTINCT to Eliminate Duplicates

select DISTINCT group_concat(lot order by lot)
from `mytable`
group by product
having group_concat(tag order by tag) = '101,102';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.