Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select Distinct query 1

Status
Not open for further replies.

JonoB

Programmer
May 29, 2003
147
GB
I have a select distinct query as follows:

SELECT DISTINCT [MergeString] FROM qryMergeTime

Whilst this does return the right records (i,e. only shows unique records in the [MergeString] field, it doesnt show all the fields that I need to see, i.e. the SELECT DISTINCT function needs to run on the [MergeString] field, but I want to see the results from the [FullString] field.

So, what I have thought of doing was as follows, but I am not sure if this would actually work

SELECT [FullString]
FROM qryMergeTime
WHERE [MergeString] In (SELECT DISTINCT [MergeString] FROM qryMergeTime)

I did try it out, and it runs very very slowly - there are 100,000 records or so...

Any ideas on how I can get the results that I am looking for?

Many thanks for your help.
 
Why can you not select both FullString and MergeString? If there are a number of FullStrings for each MergeString have you any preference for which is returned?
 
The reason why I cannot select both FullString and MergeString is that *every* FullString is unique.

i.e. if I do
SELECT DISTINCT FullString, MergeString from qryMergeTime;

or if I do
SELECT DISTINCT FullString from qryMergeTime;

then I will return every single record. Which is not what I am trying to achieve.
 
You may try either:
SELECT MergeString, First(FullString) FROM qryMergeTime GROUP BY MergeString
or:
SELECT MergeString, Last(FullString) FROM qryMergeTime GROUP BY MergeString
or:
SELECT MergeString, Min(FullString) FROM qryMergeTime GROUP BY MergeString
or:
SELECT MergeString, Max(FullString) FROM qryMergeTime GROUP BY MergeString

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Perfect!

Sometimes the most simple answers are the right ones.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top