如何删除重复的列

时间:2013-12-07 15:06:26

标签: mysql

我有一些像Sql Fiddle这样的表。

我希望此表仅选择以下值(删除重复项):

from | to
46  0  
46  18  
46  50  
46  39  
46  11   
46  12  
46  56

我使用DISTINCT关键字,但这会返回以下值:

46  0  
46  18  
46  50  
46  39  
46  11  
11  46  
46  12  
46  56

1 个答案:

答案 0 :(得分:3)

<强> Greatest and Least

SELECT distinct greatest(`from`,`to`),least(`from`,`to`)
from `tsk_private_message`

<强> SQL FIDDLE