Advertisement Jump to content
Sign in to follow this  

[SQL] Help with duplicates

This topic is 4892 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I'm doing a query in MS SQL. I'm trying to pull address lists for mailing. The issue is, we have multiple contacts for the same company we want to send mail to, and we just want one contact from one company. So my question is, how do I tell the SQL server to just send me back 1 contact to the company instead of all of them? Thanks!

Share this post

Link to post
Share on other sites


The DISTINCT keyword is used to return only distinct (different) values.

Share this post

Link to post
Share on other sites
Original post by chbrules
That's what I'm using already, doesn't work.

Ok, can you post your query?

You can also look into specifing a LIMIT and/or using subqueries in your WHERE clause (maybe with EXISTS/NOT EXISTS, ANY, IN, SOME).

Share this post

Link to post
Share on other sites
There is no LIMIT in MSSQL. Here's my query:

SELECT DISTINCT c1.Company,c1.Contact,c1.Address1,isnull(c1.Address2,'') Address2,c1.City,c1.State,c1.Zip,c2.contsupref
FROM contact1 c1
inner join contsupp c2 on c1.accountno = c2.accountno
WHERE = 'E-mail Address'
AND c2.contsupref != 'NULL'
AND c1.Contact != 'NULL'
AND c1.Address1 != 'NULL'
AND c1.City != 'NULL'
AND c1.State != 'NULL'
AND c1.State = 'CA'
AND c1.Zip != 'NULL'
c1.title LIKE '%Council%'
OR c1.title = 'city clerk'
OR c1.title = 'city manager'

The 'contsupref' field is the only unique field preventing the DISTINCT from working. Each duplicate contact may have a different email. I tried it without the email and all the duplicates are gone.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!