W
wgoldfarb
I have a Query created with the Access Query designer. What I am trying to do
is the following: I have a table of 'leads', consisting of information
including a property address and an Owner ID. I have a separate 'owners'
table with detailed information for each owner (name, address, etc). Both
tables are linked through an owner ID numeric index field. Each owner could
have more than one property, but each property has only one owner.
As a slight complication, all addresses (property addresses in the 'leads'
table and owner addresses in the 'owners' table) include a city, and there is
a separate, linked table with the names of relevant cities. So, the 'leads'
table and 'owners' table don't include the city name or details, but instead
simply have a City ID field which links into the 'cities' table.
I created a query (using the query designer in Access) that selects all
leads of a certain status. The SQL statement created by access is the
following:
SELECT leads.leadID, leads.status, leads.occupancy, leads.homeaddress1,
cities_1.cityname, leads.homestate, owners.name, owners.salutation,
owners.address1, owners.careof, cities.cityname, owners.state,
owners.postalcode
FROM (cities RIGHT JOIN owners ON cities.cityID = owners.City) INNER JOIN
(leads LEFT JOIN cities AS cities_1 ON leads.Homecity = cities_1.cityID) ON
owners.ownerID = leads.owner
WHERE (((leads.status)=1) AND ((leads.occupancy) Between 2 And 3))
ORDER BY leads.leadID;
This seems a bit complicated, and could probably be made simpler, but not
being very familiar with SQL statements I decided not to fool around with it.
What I would like to do next is eliminate any duplicate owners. In other
words, if there is an owner with more than one property, I would only like
the query to include only one property for that owner (it does not matter
which property).
I have read several ways of doing it (including a "FIRST" or "LAST"
statement, or first doing a SELECT DISTINCT on the owners table and using the
results of that instead of the owners table) but all the examples I have seen
are very simple, so I really don't know how to modify this SQL statement to
use any of those possibilities.
Any help will be greatly appreciated.
Thanks!
is the following: I have a table of 'leads', consisting of information
including a property address and an Owner ID. I have a separate 'owners'
table with detailed information for each owner (name, address, etc). Both
tables are linked through an owner ID numeric index field. Each owner could
have more than one property, but each property has only one owner.
As a slight complication, all addresses (property addresses in the 'leads'
table and owner addresses in the 'owners' table) include a city, and there is
a separate, linked table with the names of relevant cities. So, the 'leads'
table and 'owners' table don't include the city name or details, but instead
simply have a City ID field which links into the 'cities' table.
I created a query (using the query designer in Access) that selects all
leads of a certain status. The SQL statement created by access is the
following:
SELECT leads.leadID, leads.status, leads.occupancy, leads.homeaddress1,
cities_1.cityname, leads.homestate, owners.name, owners.salutation,
owners.address1, owners.careof, cities.cityname, owners.state,
owners.postalcode
FROM (cities RIGHT JOIN owners ON cities.cityID = owners.City) INNER JOIN
(leads LEFT JOIN cities AS cities_1 ON leads.Homecity = cities_1.cityID) ON
owners.ownerID = leads.owner
WHERE (((leads.status)=1) AND ((leads.occupancy) Between 2 And 3))
ORDER BY leads.leadID;
This seems a bit complicated, and could probably be made simpler, but not
being very familiar with SQL statements I decided not to fool around with it.
What I would like to do next is eliminate any duplicate owners. In other
words, if there is an owner with more than one property, I would only like
the query to include only one property for that owner (it does not matter
which property).
I have read several ways of doing it (including a "FIRST" or "LAST"
statement, or first doing a SELECT DISTINCT on the owners table and using the
results of that instead of the owners table) but all the examples I have seen
are very simple, so I really don't know how to modify this SQL statement to
use any of those possibilities.
Any help will be greatly appreciated.
Thanks!