I have two tables...
one (PEOPLE) holds the first and last names of wives and husbands. The other (ADDRESSES) holds addresses.
the PEOPLE table has fields which hold an id number to an address and they also hold id numbers matching the individules to their spouse. For instance:
PEOPLE table
peopleID || Fname || Lname || Add_code || Spouse_ID
1 Tom Jones 1 2
2 Jill Jones 1 1
3 Gary Thomas 2 4
4 Julie Thomas 2 3
5 John Smith 3 6
6 Lori Smith 3 5
ADDRESS table
adID || Addr || City || State
1 123 main Sacramento CA
2 234 Lincoln Ave Phoneix AZ
3 454 Euclid Seattle WA
I want to pull data for a mailing list... but I only want to send one copy to each address, not each person...
so I want a list like:
Tom & Jill Jones 123 main Sacramento, CA
Gary & Julie Thomas 234 Lincoln Ave Phoneix, AZ
John & Lori Smith 454 Euclid Seattle, WA
I used this query...
SELECT Fname, Lname, Addr, City, State FROM ADDRESS INNER JOIN PEOPLE ON adID = Add_code
but what that returns is seach name matched to each address...
Tom Jones 123 main Sacramento, CA
Jill Jones 123 main Sacramento, CA
Gary Thomas 234 Lincoln Ave Phoneix, AZ
Julie Thomas 234 Lincoln Ave Phoneix, AZ
John Smith 454 Euclid Seattle, WA
Lori Smith 454 Euclid Seattle, WA
How can I change the Query so that it will return only one row for each address but get the first name (and last name in case it is different) for both spouses that match the address?
(I know I could do it in PHP after pulling the data out... but I would like to do it all in the SQL statement if possible)
Would i need to make a temporary table. or sub query to match the spouses first and them join to the addresses? how woudl I do that if that is the answer?
Thanks!