rss feed Rss FeedAsp.net Coder
learn asp.net & visual studio 2008,this blog share our study record.there are a lot of solution and source code of building web application using asp.net

Distinct Recordz?

Author:kklung  PostAt:Wed, 26 Nov 2008 10:09:44 GMT Posted In:DataControls
Q:

Hi, Wish if some one could help me I have a table which contains name, tel, email
i need to import only records which have distinct email.
I do need need to import data of all three fields but only which has distinct email.
So need only records which have distinct email.
Please help .......

A:

Select distinct email,.... from table

 

Select * from table group by email. 

A:

can you give an example, how you want the records. there are different meaning of your asking.

suppose a table is like this

id fEmail         NAme

1   abcd          tony

 2  efg             raj

 3  abcd         mike

 4 efg             dennis

 what's your output?

if it is,  

abcd

efg

then by the query "select distinct email from tablename" you can get the above result.

if your output is like 1person per 1 mail,

abcd tony

efg    raj

then the query would be like this "

select Email,Name from emails e where Id=(select min(Id) from emails where Email=e.Email) "

A:

SELECT name, tel, email FROM (SELECT name, tel, email,
ROW_NUMBER() OVER(PARTITION BY email ORDER BY name) as rn
FROM  emails) t
WHERE rn=1

 
Previous: find difference in month and year in sql server 2005
--find day,month,year --for day select datediff(d,'01 may 2008',getdate()) -- --for month select datediff(m,'01 jun 2006',getdate()) -- --for year select datediff(year,'01 jun 2006',getdate()) above working fine but suppose difference is 1 year 4 month and 2 month 15... more
Next: None