TravisLaborde
IS-IT--Management
Please help if you can, with this question:
I have a table with "people" information, and a table with "people contact records." For simplicity, let's say that the people contact records are all email addresses.
I have it broken into a separate table, so that each person may have multiple email addresses listed. With a one-to-may relationship between the tables.
This works fine, but for some business purposes, there are times when we need to return a resultset including each person (once) and their "email address." Meaning, that if this person has more than one email address, we only want "the first one." We really don't care if it is the FIRST one, the LAST one, whatever, just if they have one, show it....
I am using a LEFT JOIN, but in cases where the person has multiple email addresses, of course I am getting multiple rows in my resultset. In order to limit this to returning one row per person, I have added a condition to my JOIN.. ON clause... which checks if the key = (select min(key) where ....) In effect using my join condition twice. It seems to me like there must be a better way.
Can anyone help with this?
Thanks,
Travis
I have a table with "people" information, and a table with "people contact records." For simplicity, let's say that the people contact records are all email addresses.
I have it broken into a separate table, so that each person may have multiple email addresses listed. With a one-to-may relationship between the tables.
This works fine, but for some business purposes, there are times when we need to return a resultset including each person (once) and their "email address." Meaning, that if this person has more than one email address, we only want "the first one." We really don't care if it is the FIRST one, the LAST one, whatever, just if they have one, show it....
I am using a LEFT JOIN, but in cases where the person has multiple email addresses, of course I am getting multiple rows in my resultset. In order to limit this to returning one row per person, I have added a condition to my JOIN.. ON clause... which checks if the key = (select min(key) where ....) In effect using my join condition twice. It seems to me like there must be a better way.
Can anyone help with this?
Thanks,
Travis