wasn’t sure whether to put this in Software or here, so I figured I’d start here I know this will be a straightforward answer from you SQL geniuses…
I have a table, it contains contacts that I import on a daily basis. I will have an ASP.NET front end for user interaction. From this table, my intention is to send them all mailers – but only one to each address. So my end result is a user enters a date (which corresponds to teh date imported) and they are given a resultant grid that has all the unique addresses associated to that date. I only want to send a mailer to that address once – many times my original imported list will contain multiple businesses at the same address.
Table: ContactTable
Fielsd:
ID, CompanyName, Address, City, State, Zip, Phone
I can use the SELECT DISTINCT clause, but I need all the data associated to it (company name, etc.)
I have over 262000 Records in this table.
If I select a sample date of 1/10/2011, I get 2401 records. SELECT DISTINCT Address from the same date gives me 2092 records. This is workable, I would send those 2092 people a mailer.
Secondly, I’d have to be able to historically check if a mailer was already sent to that address as well. I would not want to send another mailer to the same business tomorrow either.
What’s my best way?
I would select, then remove, the duplicates like this:
or something like this.
This will keep the first ID of the redundant address, just replace the
SELECTwithDELETEwhen ready.EDIT: Of course this will only work on exact matches.
EDIT2: If you wanted to only check where you hadn’t sent mailers, you should join both to a table of sent mailers from a specified date range