Re: display each record only once
- From: Marshall Barton <marshbarton@xxxxxxxxxx>
- Date: Mon, 19 Jun 2006 14:00:11 -0500
Gnowor wrote:
Got a report that spits out the names and info for a bunch of sales agents
that cover a certain city (which is selected by the user via a pop up form)
Problem is, I want to sort that list of agents based out when they last
recieved a sale, without seeing duplicate info for each agent.
Really working with 3 tables.
Table 1: AgentList - Contains Agent Info and Unique agent name
Table 2: CityList - Has field linked to agent name in AgentList, and 1
record for each city they cover. This works fine.
Table 3: SalesList - Has field linked to agent name in AgentList, and 1
record for the date of each sale they completed (i.e. John Smith - 05/2006,
John Smith - 04/2006, Jane Smith - 03/2006, John Doe - 04/2006, John Doe -
03/2006)
Let's say that all those agents I just listed cover New York. I want it to
spit them out in the order
Jane Smith - 03/2006
John Doe - 04/2006
John Smith - 05/2006
based on their most recent sale, and I don't want to see duplicate entries
(i.e. for John Smith - 04/2006)
Right now, I'm getting the duplicate info, like
John Smith - 05/2006
John Smith - 04/2006
John Doe - 04/2006
Jane Smith - 03/2006
John Doe - 03/2006
I think you want to use a query like:
SELECT AgentList.AgenName,
CityList.CityName,
Max(SalesList.SaleDate) As LatestSale
FROM (AgentList LEFT JOIN CityList
ON AgentList.AgenName = CityList.AgenName)
LEFT JOIN SalesList
ON AgentList.AgenName =SalesList.AgenName
GROUP BY AgentList.AgenName, CityList.CityName
Depends on your detailed needs, you might want to use INNER
JOIN instead.
--
Marsh
MVP [MS Access]
.
- Follow-Ups:
- Re: display each record only once
- From: Gnowor
- Re: display each record only once
- Prev by Date: Re: Same report with two data sets -- link to SQL basics
- Next by Date: Many subreports slowing report Open
- Previous by thread: Re: Via combo box view grouped info -- limit combo on enter, show all when leave
- Next by thread: Re: display each record only once
- Index(es):
Relevant Pages
|