Hi,
I've been puzzling out the problem below for several hours and it's driving me mad. I know there is a way to do what I want I just can't figure it out.
Here's the situation. I have the following tables:
tbl_Group, tbl_Coordinator , tbl_GroupCoordi nator, tbl_PAddress, tbl_EAddress, tbl_GroupPAddre ss tbl_GroupEAddre ss and tbl_Coordinator EAddress.
This allows for one group to have many coordinators and one coordinator to belong to many groups, a similar set with the P and E addresses.
Given a specific group ID I want to retrieve all group details and coordinator details from these tables. In my database at present I have one group. This group is correctly linked to three EAddresses and 1 PAddress. The group is linked to the only coordinator on the system and the coordinator in turn is linked to 3 EAddresses. The data itself is as I expect it to be. My trouble is the SQL;
This results in 8 rows not 1. I get 8 rows showing each of the Group EAddresses along side one of the Coordinator EAddresses.
I know it's possible to do what I want, I've even managed it before but today for some reason I cannot figure it out, and can't remember where I did before to check the solution.
Any help on this is greatly appreciated.
Cheers
nathj
I've been puzzling out the problem below for several hours and it's driving me mad. I know there is a way to do what I want I just can't figure it out.
Here's the situation. I have the following tables:
tbl_Group, tbl_Coordinator , tbl_GroupCoordi nator, tbl_PAddress, tbl_EAddress, tbl_GroupPAddre ss tbl_GroupEAddre ss and tbl_Coordinator EAddress.
This allows for one group to have many coordinators and one coordinator to belong to many groups, a similar set with the P and E addresses.
Given a specific group ID I want to retrieve all group details and coordinator details from these tables. In my database at present I have one group. This group is correctly linked to three EAddresses and 1 PAddress. The group is linked to the only coordinator on the system and the coordinator in turn is linked to 3 EAddresses. The data itself is as I expect it to be. My trouble is the SQL;
Code:
SELECT a.ID as groupID, a.name as groupName, b.ID as coordinatorID, b.title, b.firstName, b.lastName, c.organisation, c.line1, c.line2, c.line3, c.line4, c.town, c.county, c.countryID, c.postcode, d.eAddress as gpTel, e.eAddress as gpMob, f.eAddress as gpEmail, g.eAddress as cdTel, h.eAddress as cdMob, i.eAddress as cdEmail FROM tbl_Group a LEFT OUTER JOIN tbl_GroupCoordinator j ON j.groupID = a.ID LEFT OUTER JOIN tbl_Coordinator b ON b.ID = j.coordinatorID LEFT OUTER JOIN tbl_GroupPAddress k ON k.groupID = a.ID LEFT OUTER JOIN tbl_PAddress c ON c.ID = k.pAddressID LEFT JOIN tbl_GroupEAddress l ON l.groupID = a.ID LEFT OUTER JOIN tbl_EAddress d ON d.ID = l.eAddressID AND d.eAddressType = 1 LEFT OUTER JOIN tbl_EAddress e ON e.ID = l.eAddressID AND e.eAddressType = 2 LEFT OUTER JOIN tbl_EAddress f ON f.ID = l.eAddressID AND f.eAddressType = 3 LEFT JOIN tbl_CoordinatorEAddress m ON m.coordinatorID = b.ID LEFT OUTER JOIN tbl_EAddress g ON g.ID = m.eAddressID AND g.eAddressType = 1 LEFT OUTER JOIN tbl_EAddress h ON h.ID = m.eAddressID AND h.eAddressType = 2 LEFT OUTER JOIN tbl_EAddress i ON i.ID = m.eAddressID AND i.eAddressType = 3 WHERE a.ID = 1 ;
I know it's possible to do what I want, I've even managed it before but today for some reason I cannot figure it out, and can't remember where I did before to check the solution.
Any help on this is greatly appreciated.
Cheers
nathj
Comment