MySQL查询返回重复的行
我有一个表MySQL查询返回重复的行,mysql,sql,join,Mysql,Sql,Join,我有一个表mytable,如下所示 ╔═════════╦══════╦═════╗ ║ product ║ tag ║ lot ║ ╠═════════╬══════╬═════╣ ║ 1111 ║ 101 ║ 2 ║ ║ 1111 ║ 102 ║ 5 ║ ║ 2222 ║ 103 ║ 6 ║ ║ 3333 ║ 104 ║ 2 ║ ║ 4444 ║ 101 ║ 2 ║ ║ 5555 ║ 101 ║ 2 ║
mytable
,如下所示
╔═════════╦══════╦═════╗
║ 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 ║
╚═════════╩══════╩═════╝
我有输入101
,102
。我想要像这样的输出
2,5
6,8
我有一个疑问像
select group_concat(lot order by lot)
from `mytable`
group by product
having group_concat(tag order by tag) = '101,102';
它回来了
2,5
2,5
6,8
我只想要一个,而不是两个2,5
,以避免重复行。我该怎么做
这是小提琴如果你想
与众不同
那么
select distinct group_concat(lot order by lot)
from `mytable`
group by product
having group_concat(tag order by tag) = '101,102';
您只需使用
DISTINCT
即可消除重复项
select DISTINCT group_concat(lot order by lot)
from `mytable`
group by product
having group_concat(tag order by tag) = '101,102';
尝试
selectdistinctivegroup\u concat(按批次排序)
。太棒了。可能是@GiorgosBetsos的复制品,它起作用了。请将其作为答案发布,以便我可以接受。请随意接受已发布的答案。