Need to select top 5 rows

  • Thread starter Thread starter AJ
  • Start date Start date
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
 
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?
 
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.)
 
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?
 

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

Similar Threads

aggregate error? 2
Only return top 5 records per category 1
AVG TOP 5 Query 2
select top 5 1
SELECT SQL, can you have two 3
acess sum 7
Aggregate Function Error 0
Top 25 Brokers for each MMPM query 1

Back
Top