2012-10-01 95 views
0

假設我在桌子上有這些。如何從MySQL選擇獨特的組合?

Index Resultant First Second 
1  Ice   Water  Cold 
2  Cold Air Water  Cold 
3  Cold Wind Water  Cold 
4  Hot Air  Volcano  Air 
5  Normal Air Oxygen  Hydrogen 
6  Ice   Cold  Water 
7  Cold Air Cold  Water 
8  Cold Wind Cold  Water 

我想這些

Index Resultant First Second 
1  Ice   Water  Cold 
2  Cold Air Water  Cold 
3  Cold Wind Water  Cold 
4  Hot Air  Volcano  Air 
5  Normal Air Oxygen  Hydrogen 

因爲底部3區域中的所有副本,如果你翻轉過來,他們只顯示。但我不想讓第1,2行被隱藏,因爲它也是水和冷的結合。

回答

6
select least(col1, col2), greatest(col1, col2) 
from MyTable 
group by least(col1, col2), greatest(col1, col2) 

SQL Fiddle Example