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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

selecting rows ina query where only the 1st field is distinct 1

Status
Not open for further replies.

spleenboy

Programmer
Nov 10, 2004
3
GB
I'm an Oracle developer who is trying to get to grips with Access!
I need to select records in a multi table query where it only checks that one field is unique i.e.

col1 col2
10 apple
10 orange
20 grapes
20 pears

I need it to return just 2 records, 1 for value for 10 and 1 for key 20. It doesn't matter which one of the rows it returns as long as it returns just one distinct value for values in col1. Because the composite values in the column are unique, access returns all rows. This is very simple to do in Oracle, but I can't get Access to play ball.
Any ideas??

 
spleenboy,

You just want the distinct set of values in Col1 ??

SELECT DISTINCT col1 FROM YourTable

Mordja
 
Kind of. I need the distinct values from col1, and any value from col2 i.e.

10 orange
20 grapes

I am happy with any combination as long as I only get 1 distinct value for col1.
Also, both columns are coming from diferent tables. I dont know if this complicates things in access.
 
spleenboy,

Provide a little more information about your two tables, ie their relationship and some sample data.

Mordja
 
SELECT col1, Min(col2) As AnyCol2
FROM yourTable
GROUP BY col1;

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks PHV. That is very useful.Out of interest, I am use to working with standard SQL within an Oracle database. What does Access use? It seems to be a strange flavour of SQL.
Also, what does AnyCol2 do in the example you gave?
 
what does AnyCol2 do in the example you gave
Its an alias for the calculated column.
The SQL code I posted is pure standard ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top