The first() function

N

Not Me

Hi,

When using the first() function, either on a table directly or on a ordered
table, the results are the same.

Why is this? I thought it could be used on ordered results to pick the first
record of many groups?

Please help,
Chris
 
V

Van T. Dinh

Nope. First means the first in the internal order which we don't know. Use
Min or Max instead.

I never used First except in Totals ("Group By") Query where I know all the
values in the group are the same.
 
N

Not Me

Try using the TOP predicate in a query:

Select Top 1 From Table1 Order By FieldWhatever;

Cheers, but it needs to work within a group by query. I want the top of each
group y'see...

Chris
 
R

Rick Brandt

Not Me said:
Cheers, but it needs to work within a group by query. I want the top of each
group y'see...

Have you tried using Max()? First() and Last() are fairly useless except
for cases where you want a single value from the group and don't care which
one it is.
 
N

Not Me

Rick Brandt said:
Have you tried using Max()? First() and Last() are fairly useless except
for cases where you want a single value from the group and don't care which
one it is.

Thanks, that looks like the way to go, but now I'm onto another problem.
How can I display another column, and show the record in the same row as
that Max() field?

I.e.

101 5 hello
101 3 goodbye

group by first column, choose max of second column. How do I show "hello"
in the 3rd? (If I group by 3rd col I'll get dups?)

Cheers!
Chris
 
R

Rick Brandt

Not Me said:
Thanks, that looks like the way to go, but now I'm onto another problem.
How can I display another column, and show the record in the same row as
that Max() field?

I.e.

101 5 hello
101 3 goodbye

group by first column, choose max of second column. How do I show "hello"
in the 3rd? (If I group by 3rd col I'll get dups?)

You can't do that in a single query. First create a query without the
third column and then use that query as a source for a second query where
you can add the third column in.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top