Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Order by Count of matching records 1

Status
Not open for further replies.
Jan 26, 2001
550
GB
Hi all

This is one that always gets me and I can never work out how to achieve it simply. I wonder if someone could post a simple rule to achieve the following result with a SQL query against an Access database.

I wish to return a list of PROMOTERS, but ordered by the number of matching REQUESTS from another table.

For example this is what I have, but it won't work:

Code:
SELECT * FROM PROMOTERS, COUNT(SELECT * FROM REQUESTS WHERE REQUESTS.REQUEST_PROMOTERID = PROMOTERS.PROMOTER_ID) As TotalRequests ORDER BY TotalRequests

Could someone point out where I am going wrong, and I should go about this? It seems like it should be a relatively simple operation.

Many thanks

Nick





Nick (Webmaster)

 
A starting point:
SELECT P.PROMOTER_ID, P.Field, P.AnotherField, Count(*) As TotalRequests
FROM PROMOTERS AS P INNER JOIN REQUESTS AS R ON P.PROMOTER_ID = P.REQUEST_PROMOTERID
GROUP BY P.PROMOTER_ID, P.Field, P.AnotherField
ORDER BY Count(*)


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top