Limit Records

D

DS

I want this query to return only the first ten records. How can I do this?
Thanks
DS

SELECT [CusFirstName] & " " & [CusLastName] AS CUSS, "DOLLAR" AS TYPE,
Sum(tblChecks.ChkTotal) AS SumOfChkTotal
FROM tblCustomers INNER JOIN tblChecks ON tblCustomers.CustomerID =
tblChecks.ChkCustomerID
GROUP BY [CusFirstName] & " " & [CusLastName], "DOLLAR"
ORDER BY Sum(tblChecks.ChkTotal) DESC;
 
D

DS

OK I found the Top Value thing, which I assume is what I need. But I for
the life of me can't figure out how to implement it. Any help appreciated.
Thanks
DS
 
J

John Spencer

Add Top 10 to the start of the query.

SELECT Top 10 [CusFirstName] & " " & [CusLastName] AS CUSS
, "DOLLAR" AS TYPE
, Sum(tblChecks.ChkTotal) AS SumOfChkTotal
FROM tblCustomers INNER JOIN tblChecks
ON tblCustomers.CustomerID = tblChecks.ChkCustomerID
GROUP BY [CusFirstName] & " " & [CusLastName], "DOLLAR"
ORDER BY Sum(tblChecks.ChkTotal) DESC;

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
 
G

Golfinray

If you go to the query properties (right click in the area where the tables
or queries go) and select top values then top 10 that should get it.
 
J

John Spencer

The Top records are determined by the sort order imposed in the Order By
clause. In Access Top 10 returns ties (so if the nth value is
duplicated, all those records with the nth value will be returned.

If you want to get only 10 then add more fields to the Order By clause.
With your query you only real choice is to add
[CusFirstName] & " " & [CusLastName]
To the sort order.

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================


John said:
Add Top 10 to the start of the query.

SELECT Top 10 [CusFirstName] & " " & [CusLastName] AS CUSS
, "DOLLAR" AS TYPE
, Sum(tblChecks.ChkTotal) AS SumOfChkTotal
FROM tblCustomers INNER JOIN tblChecks
ON tblCustomers.CustomerID = tblChecks.ChkCustomerID
GROUP BY [CusFirstName] & " " & [CusLastName], "DOLLAR"
ORDER BY Sum(tblChecks.ChkTotal) DESC;

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================

I want this query to return only the first ten records. How can I do
this?
Thanks
DS

SELECT [CusFirstName] & " " & [CusLastName] AS CUSS, "DOLLAR" AS TYPE,
Sum(tblChecks.ChkTotal) AS SumOfChkTotal
FROM tblCustomers INNER JOIN tblChecks ON tblCustomers.CustomerID =
tblChecks.ChkCustomerID
GROUP BY [CusFirstName] & " " & [CusLastName], "DOLLAR"
ORDER BY Sum(tblChecks.ChkTotal) DESC;
 
K

KARL DEWEY

Other ways are to click in the icon that reads 'All' when you have the query
open in design view and type in 10.
In the SQL view enter TOP X like this --
SELECT TOP 10 [tableName].[FirstField], [SecondField], ....
 

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


Top