Results 1 to 2 of 2
  1. #1
    cshannon is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Feb 2014
    Posts
    2

    Help on Access Subquery

    I have a database that contains customer information for a company. Each customer is associated with a company sales rep. For example, customer a may be associated with rep #20, customer b may be associated with rep #30, and customer c my also be associated with rep #20. I am needing to write a query containing a subquery to determine which rep has the most customers.



    So I assume my subquery will count the customers of each rep, and group them by rep num, as so:

    SELECT COUNT(CustomerName) AS TotalCustomers
    FROM Customer
    GROUP BY RepNum

    But then I don't know how to write a query over that to pull the RepNum of the rep that has the most customers. Please help!!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Try:

    SELECT TOP 1 RepNum, Count(CustomerName) AS TotalCustomers FROM Customers GROUP BY RepNum ORDER BY Count(CustomerName) DESC;
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 11
    Last Post: 11-08-2013, 06:14 PM
  2. Access WITH subquery
    By johnseito in forum Access
    Replies: 5
    Last Post: 10-15-2013, 08:41 PM
  3. Subquery
    By tomclavil in forum Queries
    Replies: 3
    Last Post: 02-27-2012, 03:05 AM
  4. Access SQL Subquery Problem
    By dfenton21 in forum Access
    Replies: 2
    Last Post: 07-26-2011, 07:54 AM
  5. Access Subquery Max Date/Time field
    By ruci1225 in forum Access
    Replies: 1
    Last Post: 04-08-2011, 07:33 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums