2016-01-20 40 views
1
select distinct t.id, 
t.name, 
t.location, 
t.country 
from table t 

说我有这样的查询上面,在这里我想对所有的SELECT语句的唯一不同的值,除非该国为“美国”,那么希望所有的与该国对应的值。这甚至有可能吗?你能选择所有不同的行,然后根据1个异常包含一些倍数吗?MySQL的 - 选择所有重复行除1

+0

我提出一个答案试试,但我认为你应该在欲望输出采样数据,因为我没有看到如何,这将是有用的。所以我猜你的*真实*问题是不同的 –

回答

1

也许你想与UNION ALL

select distinct t.id, 
     t.name, 
     t.location, 
     t.country 
from table t 
WHERE country <> 'US' 

UNION ALL 

select t.id, 
     t.name, 
     t.location, 
     t.country 
from table t 
WHERE country = 'US'