Need to select top 5 rows

A

AJ

I want to set up a select to get the sum of a value but I only want to sum up
the first 5 rows.

Example:

select sum(x)
from tableA
where **ROWCOUNT <= 5
order by y

Is this possible in VBA/Access?? Example? Thanks
 
A

AJ

Thanks Karl - If I do that I get the error "you tried to execute a query that
does not include the specified expression 'Y' as part of an aggregate
function. Any ideas?
 
A

Allen Browne

AJ said:
Damn....no same error.

Sum(x) without any GROUP BY will yield only one record.
Which Y do you expect to see with that total?

GROUP BY y.
Or perhaps try First(y)

(It also helps to explicitly alias aggregated fields.)
 
A

AJ

Hello Allen: I understand that sum will only return one record and I want to
only sum the first five rows, based on column Y.
Can this be done?
 
Top