sql distinct命令不正确的结果 [英] sql distinct command improper result
问题描述
亲爱的先生,
有一个表名是mobilecollection,其中我有mobileno,id,name,area我想从这个表中提取唯一的mobileno。所以我使用了这个命令:
Dear sir,
have one table name is mobilecollection in which i have mobileno, id, name, area i want to extract unique mobileno from this table . so i used this command :
Select distinct mobileno from mobilecollection
它给了我包含的结果所有独特的mobileno但我希望得到另一列与各自的行,所以我使用下一个命令然后从mobilecollection中选择不同的mobileno,id,name,area但是它给出的结果是不正确的,因为所有行的结果都是unqiue但我期待得到这样的结果..独特的移动没有。与各自的专栏。
PLZ给我解决方案我在任何地方都找不到。
谢谢
it has given me the result consisting the all unique mobileno but i want to get the other column with the respective rows so i used the next command then Select distinct mobileno,id,name,area from mobilecollection but the result which it has given was improper cause the result was unqiue for all rows but i was expecting to get the result like this.. unique mobile no. with those respective columns .
plz give me solution i did not find this anywhere.
thanks
推荐答案
试试这个:
Try this:
select a.* from mobilecollection a
inner join
(
select distinct mobileno, min(id) as id from mobilecollection
group by mobileno
) as b
on a.mobileno = b.mobileno
and a.id = b.id
您好VishvaDeepak ,
试试这个链接 [ ^ ] ;-)
问候,
RK
Hi VishvaDeepak,
Try this Link[^] ;-)
Regards,
RK
这篇关于sql distinct命令不正确的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!