Click here to Skip to main content
16,016,580 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 :
SQL
Select distinct mobileno from mobilecollection 


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
Posted
Updated 4-Jun-13 22:41pm
v2
Comments
CHill60 5-Jun-13 4:55am    
_Amy's solution below will give you a list of unique mobile numbers but the rest of the rows will contain just the first id, name, area that has that number. I would add count(*) as cnt in the inner query and use select a.*, b.cnt from .. in the outer query - at least that way you'll get positive indication of duplicated numbers

Try this:
SQL
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 



--Amit
 
Share this answer
 
v2
Hi VishvaDeepak,

Try this Link[^] ;-)

Regards,
RK
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900