UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> distinct query with a difference    
 
   
gideon
post Nov 22 2005, 07:57 AM
Post #1

UtterAccess Veteran
Posts: 362
From: Brazil



I need to create a distinct query with the following peculiarities.

Idcode, Source, description.

The Source can have repetitive Idcodes making for apparent duplicates. So I then combine the two with a query creating a unique code.

ucode : [idcode] & [source]

Ucode, Idcode, Source, Description

That then provides me with a unique key. Other than creating a temporary table with no duplicates allowed and doing a make table query how can I have destinct on the Ucode but include the other fields. The total with min, max, last etc. do not work. Who has any ideas please.
Go to the top of the page
 
+
jsitraining
post Nov 22 2005, 08:01 AM
Post #2

UtterAccess VIP
Posts: 5,230
From: Scotland (Sunny Glasgow)



Show us the sql of what you have tried please.
Go to the top of the page
 
+
PaulBrand
post Nov 22 2005, 08:11 AM
Post #3

UtterAccess Ruler
Posts: 1,585
From: Oxford UK



Create another query with this as the source
Go to the top of the page
 
+
fkegley
post Nov 22 2005, 08:54 AM
Post #4

UtterAccess VIP
Posts: 23,583
From: Mississippi



Have you tried creating a distinct query that fetches Idcode and Source as separate fields? That would give you one row for each different combination, too. Then another query that joins this query back to the table on the Idcode and source fields to get the rest of the fields that you need.
Go to the top of the page
 
+
gideon
post Nov 22 2005, 11:11 AM
Post #5

UtterAccess Veteran
Posts: 362
From: Brazil



I did just that.

Once I have the query result with just one unique code, I then use that as the basis for my next query, When joining them I end up with all the records again.

This is the initial code combine query structure


Query name "Ucode" (Returns some 1,090,000 records)

SELECT [IDcode] & [Source] AS Ucode, system.Source, system.IDcode, system.description
FROM system;


Then to obtain the Unique code I use

Query name "Ucode Distinct" (Retuns some 480 Records)

SELECT DISTINCT Ucode.Ucode
FROM Ucode;

Now to combine them again into this

Ucode, Idcode, Source, Description

Final query (Returns all the 1,090,000 records)

SELECT [ucode distinct].Ucode, Ucode.EventSource, Ucode.EventID, Ucode.EventText
FROM [ucode distinct] LEFT JOIN Ucode ON [ucode distinct].Ucode = Ucode.Ucode;


This is where things just dont go my way.
Go to the top of the page
 
+
fkegley
post Nov 22 2005, 01:45 PM
Post #6

UtterAccess VIP
Posts: 23,583
From: Mississippi



I'm talking about doing this:

SELECT DISTINCT [TableName].IDCode, [TableName].Source FROM [TableName]

SELECT blah blah blah FROM DistinctQuery JOIN [TableName] ON [DistinctQuery].IDCode = [TableName].IDCode AND [DistinctQuery].Source = [TableName].Source
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 22nd May 2013 - 06:00 AM