Finding one record for a specific field

J

Jan

Hi,

I have this database with 112,000 records. Of those records, one of the
fields (Call it CCN) can have 1 record for a CCN or numerous records for the
same CCN. I want to identify all the CCNs that only have one related record
and export to Excel. How do I write the SQL to return only the CCNs that have
one related record?

Thanks!
 
M

MGFoster

Jan said:
Hi,

I have this database with 112,000 records. Of those records, one of the
fields (Call it CCN) can have 1 record for a CCN or numerous records for the
same CCN. I want to identify all the CCNs that only have one related record
and export to Excel. How do I write the SQL to return only the CCNs that have
one related record?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Huh?! You have a TABLE w/ 112K rows. A database contains tables, which
contain rows (records). A field (column) cannot "have" a record (row),
since a column is PART of a row, not the other way around. What I guess
you're trying to say is "You want to retrieve all rows (records) that
have the same value in the CCN column (field)." You'd do something like
this:

SELECT <column list>
FROM <table name>
WHERE CCN = <value you're looking for>

Substitute your column/table names where appropriate; and the CCN value
you're looking for.

If CCN contains strings put quotes around the value:

WHERE CCN = 'my value'

Save the query & then use the TransferSpreadsheet command to transfer
the data to Excel; or, use the File > Export... command to do the same
thing.

Read a good book on database design (or just the Access Help file's
article "Ways to get started if you're using a database for the first
time") so you can get the nomenclature and we can understand what the
heck you're trying to ask.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQpNvhIechKqOuFEgEQLy+ACfYSXfVQXWGoPa2kyEM52Mq+VOl2UAmwQ+
gSKDhXs8wheWoJdU/vWPCOwD
=taDA
-----END PGP SIGNATURE-----
 
J

John Spencer (MVP)

If I understand what you are looking for, you need a query that looks something
like the following. Substitute your table and field names.

SELECT YourTable.*
FROM YourTable
WHERE YourTable.CCNFIELD IN
(SELECT Tmp.CCNFIELD
FROM YourTable as Tmp
GROUP BY Tmp.CCNField
HAVING COUNT(Tmp.CCNField) = 1)
 
Top