»
 

Go Back   ResellerRatings Store Ratings > ResellerRatings Forums > Tech Support

Reply
 
LinkBack Thread Tools Display Modes
Old 08-18-2003, 06:04 AM   #1 (permalink)
Registered User
 
Join Date: Aug 2003
Posts: 1
The Unknown is on a distinguished road
DISTINCT in Access question

Hello. I'm making a module to load info from a spreadsheet into the right tables. I have a query that looks like this:
Code:
Set orig_clients = CurrentDb.OpenRecordset( _
        "(SELECT name, ssn, number, status FROM table WHERE (name IS NULL OR ssn IS NULL) AND number IS NOT NULL)" _
        & " UNION " _
        & "(SELECT DISTINCT name, ssn, number, status FROM table WHERE number IS NOT NULL AND name IS NOT NULL AND ssn IS NOT NULL)" _
        & "ORDER BY number")
It takes all the distinct entries where the name and ssn is defined and all the entries where name or ssn is null and loads them together in one set. My problem is I want the number column but if two names have two different numbers, the names will repeat. How can I find all the distinct names but also load the numbers?

Any help would be greatly appreciated

The Unknown is offline   Reply With Quote
Old 08-18-2003, 06:12 PM   #2 (permalink)
Registered User
 
Join Date: Sep 2002
Posts: 265
Creosote is on a distinguished road
I don't quite understand your question...but here is a rundown of DISTINCT.

DISTINCT will select rows based on the entire display result. So whatever fields you choose to display, it will evaluate all of them for their uniqueness.

So basically, I don't know what you are asking. Do you want multiple entries for each name? Or do you want the sum of the numeric columns for each name?
Creosote is offline   Reply With Quote
Old 08-19-2003, 01:09 PM   #3 (permalink)
Registered User
 
Join Date: Oct 2001
Location: TOO close to Wash DC
Posts: 7,956
vass0922 is on a distinguished road
distinct should give you exactly what you're asking for.
If you include the number column AND those numbers are different in each row it will give you seperate records for the two rows in the spreadsheet.
__________________
<< Insert exceedingly large and overly verbose message of how 1337 you are here including full specs of every vehicle you've ever driven and PC you've owned >>
vass0922 is offline   Reply With Quote
Old 09-29-2003, 11:56 AM   #4 (permalink)
Registered User
 
Join Date: Oct 2001
Location: New Hampshire, USA
Posts: 604
ctaylor is on a distinguished road
One option, not the most elegant by any means, is to run queries using docmd.openquery instead of using recordsets.

This way you could create an temporary table where the names field is indexed allowing for no duplicates.

You could then run either a series of APPEND queries (one for each case described in your UNION query), or alternately take the results of the UNION query into a second query. This second query could be converted into APPEND query writing to the temporary table.
ctaylor is offline   Reply With Quote
Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Most Active Discussions

Recent Discussions

All times are GMT -6. The time now is 10:31 PM.