auntier
10-01-2006, 07:14 PM
I'm looking for the best approach to write a query for the following scenario:
I have an account table and a contact table. The contact table has various fields such as name, phone numbers, unique id, and a primary designation that is not a required field. These records are then associated back to the account records.
I'm attempting to write a query that selects at least one contact from each account record. I can easily write the query to select the contact where the primary designation is set to yes but I'm having difficulties figuring out how to select one contact record per account record when no primary designation exists. Is it possible to write a query to select a record where the primary designation is set to yes and then if that does not exist maybe select the record with the lowest or highest id number per account?
I have an account table and a contact table. The contact table has various fields such as name, phone numbers, unique id, and a primary designation that is not a required field. These records are then associated back to the account records.
I'm attempting to write a query that selects at least one contact from each account record. I can easily write the query to select the contact where the primary designation is set to yes but I'm having difficulties figuring out how to select one contact record per account record when no primary designation exists. Is it possible to write a query to select a record where the primary designation is set to yes and then if that does not exist maybe select the record with the lowest or highest id number per account?