>Hi,
>I have two tables with one-to-many relation.
>Is there a way - in one sql statement - to count all the records
>which have only one record relation in the "many" table.
>
>Thanks.
SQL Server:
select FieldFK from ManyTable group by FieldFK having count(FieldFk) = 1
VFP:
select FieldFK, count(*) as counts from ManyTable group by FieldFK having counts = 1
If you need to select records from the main table
select MainTable.* from MainTable
INNER JOIN (select FieldFK, count(*) as counts from ManyTable group by FieldFK having counts = 1) OnlyOne
on MainTable.PKField = OnlyOne.FieldFK
If it's not broken, fix it until it is.
My Blog