私はテーブルを持っていますmytable
以下のように;MySQLクエリが重複行を返す
╔═════════╦══════╦═════╗
║ 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 2,5
、私は重複行を避け、一つだけをしたいです。これどうやってするの?ここで
フィドルhttp://sqlfiddle.com/#!9/7a78bb/1/0
を排除するために
DISTINCT
を使用する必要があります) ' –SQLFiddleは事実です。驚くばかり。 – Draco18s
[MySQLクエリは、特定のタグの組み合わせに基づいて行をフェッチする際に不要な行を返す可能性があります](http://stackoverflow.com/questions/34885425/mysql-query-returns-unwanted-rows-on-fetching-rows-based- on-specific-tag-combina) – CodeGodie