显示连接中的非重复行以及规定mysql的位置

时间:2014-03-06 20:15:05

标签: mysql

我想显示所有行,只显示重复行中的一行,但查询有一个连接和规定。

select 
     judges.judgesid, 
     judges.id, 
     judges.eventid, 
     judges.category
from judges 
left join event as eventdt 
  on judges.eventid = eventdt.eventid 
where judges.eventid = '125432' and judges.e_date = eventdt.e_date

表类似于:

e_date  | category    
1/1/2001| start    
1/1/2001| intermediate    
1/1/2001| advanced    
1/1/2001| advanced

我想要展示

e_date  | category
1/1/2001| start
1/1/2001| intermediate
1/1/2001| advanced

我尝试了区别,但我想我做错了,因为我会收到错误或所有行都会显示。

1 个答案:

答案 0 :(得分:1)

您可以将DISTINCT关键字替换为GROUP BY子句。

 select 
         judges.judgesid, 
         judges.id, 
         judges.eventid, 
         judges.category
    from judges 
    left join event as eventdt 
      on judges.eventid = eventdt.eventid 
    where judges.eventid = '125432' and judges.e_date = eventdt.e_date
       GROUP BY 
  judges.eventid, 
     judges.category;