By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,456 Members | 1,473 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,456 IT Pros & Developers. It's quick & easy.

Using first or distinct?

P: n/a
I have data like the following

1 ENID
2 ENID
3 ENID
4 GEKKO
5 GEKKO
6 SANDRA
7 ROB
8 ROB
9 ROB

The first column is the primary key and the second column is some kind of code. I would like to create a query that only gives me the first one, something like this

1 ENID
4 GEKKO
6 SANDRA
7 ROB

Of course I'm including only two columns for this example but the record has a lot of more fields.

Thanks for your help

*****************************************
* This message was posted via http://www.accessmonster.com
*
* Report spam or abuse by clicking the following URL:
* http://www.accessmonster.com/Uwe/Abu...13ffb6a5a21802
*****************************************
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Gekko . via AccessMonster.com" <fo***@AccessMonster.com> wrote in message news:<96******************************@AccessMonst er.com>...
I have data like the following

1 ENID
2 ENID
3 ENID
4 GEKKO
5 GEKKO
6 SANDRA
7 ROB
8 ROB
9 ROB

The first column is the primary key and the second column is some kind of code. I would like to create a query that only gives me the first one, something like this

1 ENID
4 GEKKO
6 SANDRA
7 ROB

Of course I'm including only two columns for this example but the record has a lot of more fields.


How about

SELECT Min(MyKey) AS MinOfMyKey, MyCode
FROM MyTable
GROUP BY MyCode;

where MyKey is your first column and MyCode is your second (code) column.

Bruce
Nov 13 '05 #2

P: n/a
That worked great!

*****************************************
* A copy of the whole thread can be found at:
* http://www.accessmonster.com/uwe/For...s-access/17303
*
* Report spam or abuse by clicking the following URL:
* http://www.accessmonster.com/Uwe/Abu...eb4f0916bfccba
*****************************************
Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.