CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: SQL Question

  1. #1
    Join Date
    Jan 2003
    Posts
    48

    Thumbs up SQL Question

    Jacob the n00b is back... I should have probably posted this on the database forum, but it doesn't seem visited often and this will be used in VB, indirectly, so...

    Background: My college needs a mailing list sent out to everyone who attended attended any of the camps its sponsored within the last few years. I've had to import an old, inefficient FoxPro database, and now have it in a regular MS Access DB format. The problem with the old database is that there is an entry for every single camper and councilor for each of his or her times attended. I.E. - I attended camp three times, from 2000 to 2002, and so I'm in the database three times.

    Problem: I need an SQL query to search through the database (which I've cleaned up significantly) and return records needed for a mailing list. There are multiple records with the same address (two sisters going to camp, or a father as a councilor and a son as a camper, etc), but I only need one record returned per mailing address. All the fields I need are contained in a single table, and I only need a few fields (fldLastName, fldStreetAddress, et cetera).

    I'm sorry I keep buggin you wonderful forum people. I don't deserve the job I have. I don't know how I even got it. I suck. I should give all the money I make to all of you... but I'm not :P I don't make enough anyway.

    -Jacob

  2. #2
    Join Date
    Jan 2003
    Posts
    48

    one quick note..

    Note that I can do multiple queries and such, that'd be no problem... or have a number of tables if necessary

  3. #3
    Join Date
    Oct 2002
    Location
    Kempton Park, South Africa
    Posts
    14
    I'm not exactly sure I understand what you want, but here goes.


    1) If you only need to get the mailing address then just run

    select disitinct (mailingAddressField) from theTable

    2) if you need that persons information then just run the same query as above, but add the key information to the distinct clause

    ex.
    select distinct firstName,LastName,IDNr,MailingAddress from theTable

    3) alternatively if you need to remove the excess records permanently, just load the 2) query into a tmpTable, delete all the records out of theTable and the load the tmpTable back into the first table

    hope it helps
    "Of all the things I've lost, I miss my mind the most" -- Ossie Osbourne

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured