Click here to Skip to main content
15,889,795 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
SQL
select vCompanyName,vemailid
 from tblmembers 

here i dont want duplicate vCompanyName
itried with distinct but not working
pls help..
Posted
Updated 6-Oct-11 19:01pm
v2
Comments
Uday P.Singh 7-Oct-11 1:22am    
Are you getting any error?
koolprasad2003 7-Oct-11 2:36am    
you can use distinct with either companyname or email_id
Bala Selvanayagam 7-Oct-11 10:13am    
vCompanyName vemailid
------------ --------
ABC a@hotmail.com
ABC c@hotmail.com
XYZ b@hotmail.com

I just put some sample data to understand your requirement and please tell me the output you needs based on the above data...company name ABC has two different email address and which one you need and why ?

You can try this:

SQL
SELECT vCompanyName, MIN(vemailid)
FROM results
GROUP BY vCompanyName
 
Share this answer
 
v2
Try this
SQL
Select tmp.vCompanyName , tblmembers.vemailid
from
(
Select vCompanyName  from tblmembers
group by vCompanyName
having count(vCompanyName) =1
) As tmp
inner join tblmembers on tblmembers.vCompanyName =tmp.vCompanyName
 
Share this answer
 
Comments
Rakesh S S 27-Oct-11 5:46am    
anarklai352
great work!!!
Here you are using distinct on entire select query means it will check whether there are any duplicate records in combination of companyname and emailid
thats why you are getting same companyname with different emailid's

if you want unique company names then use this

SQL
select distinct vCompanyName from tblmembers


hope this helps you
 
Share this answer
 
v3
Comments
Rakesh S S 7-Oct-11 1:09am    
but i want to retrive email id as well ...with same query
P.Salini 7-Oct-11 1:14am    
As far as i know it is not possible to get distinct companyname in same query in your case.
Uday P.Singh 7-Oct-11 1:32am    
agree my 5
P.Salini 7-Oct-11 1:41am    
thanks
Its not possible to get distinct companyname in the same query with emailid.

As this:

SQL
select distinct(vCompanyName),vemailid from results


will result duplicate companyname with email ids.

If you want distinct companyname then use this:

SQL
select distinct(vCompanyName)from results



hope it helps :)

for further queries comment here!
 
Share this answer
 
Variation of solution 5

select vCompanyName, MIN(vemailid) as emailid
from tblmembers 
GROUP BY vCompanyName


Notice that this may not give the email address you think it will.
 
Share this answer
 

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