Thank you all for your assistance in aiding me to create my queries
successfully. I now run accross problems when pulling my individual queries
together to create a UNION query.
My goal with the following query is to form a union of all fax numbers from
3 different sources while avoiding any duplicate fax number listings.
In the first and second portions of the query, separated by UNION, when
there are duplicates of a given fax number, I need the one with the min ID to
show. All other fields don't matter which results are displayed (I have used
First by some fields in an attempt to create distinct records when there are
duplicates in fields other than the fax number field).
In the last portion of the query, separated by another UNION, there are no
duplicate fax numbers so an aggregate function is not necessary.
Each individual query does not result in duplicates. This issue I face is
that the UNION is not avoiding duplicate entries from one portion of the
UNION query to another.
I understand that recordset variances created with the inclusion of fields
other than the fax number fields, will cause duplicate listing. This is
because 2 records will no longer be identical as it would be if only the fax
numbers were selected. However, when viewing the UNION query results, I
notice a duplication of 2 records that are identical throughout all fields in
the record except for the ID field.
(SELECT DocumentHeaders.SoldToFax,First( DocumentHeaders.SoldToCompany) As
FCompany, First(DocumentHeaders.DataSource) As FDataSource
,DocumentHeaders.Remove, First(DocumentHeaders.catagoryID) As FCatID,
Min(DocumentHeaders.ID) As MID
FROM DocumentHeaders
GROUP BY DocumentHeaders.SoldToFax, DocumentHeaders.Remove
HAVING (((DocumentHeaders.SoldToFax)<>""))
UNION
SELECT DocumentHeaders.ShipToFax, First(DocumentHeaders.ShipToCompany) As
FCompany, First(DocumentHeaders.DataSource) As FDataSource,
DocumentHeaders.Remove, First( DocumentHeaders.catagoryID) As FCatID,
Min(DocumentHeaders.ID) As MID
FROM DocumentHeaders
GROUP BY DocumentHeaders.ShipToFax, DocumentHeaders.Remove
HAVING (((DocumentHeaders.ShipToFax)<>"")))
UNION (SELECT faxnumbers.SoldToFax, faxnumbers.MSoldToCompany,
faxnumbers.DataSource, faxnumbers.Remove, faxnumbers.CatagoryID, faxnumbers.ID
FROM faxnumbers);