pysan
05-03-2005, 05:23 PM
Hi all, I have thought through this problem and just can't seem to find a solution that will not kill the resources among other things... This is a bit complex of a problem, but I will try to diagram it out as simply as possible.
Basically I have 6 tables A, B, C, D, E, F, G related as follows:
A->B, C->B, D->B, B->E, E->F, G->B
The problem I'm having is how I need the info displayed from these tables...
I have at least one field needed from each of the tables in the returned data, so that requires all the tables, with G being an optional one, so I currently have it under a LEFT JOIN from the rest, and it is working fine. A simplified query for what I am using is
SELECT DISTINCT * FROM A, B, C, D, E, F LEFT JOIN G ON G.BID=BID WHERE AID=B.AID && C.BID=BID && D.BID=BID && B.EID=EID && E.FID=FID && C='value'
I then have 3 loops in PHP as there are multiple needs from those tables
Multiple F records belong to one B record, with multiple B records belonging to 1 A record. Now that much is happening just fine, and I have what I want, except for one thing. The problem is that I need a few additional A records in between the A's I have, meaning I need a few additional records from A that are only from tables A, B, C, rather than all of them, as the rest are. So because they don't need them all, my query doesn't pull them for me. I tried playing with further LEFT JOINs but that just made a mess of it as it returned a ton more records than I need? Now I realize that perhaps subqueries would make this much easier, but I am limited because the server this needs to run on only has MySQL 3.23, and my test server has 4.02 or something, so that doesn't suppport them either.
If there is not a way to pull the required data from that single query, then the only other way I can think of doing it is to pull my primary list from A,B,C and then in the primary outer while loop run the smaller query each time through the loop. But that would take me from 1 db query hit per page to about 20+ queries against the DB, which just doesn't seem like that elegant, or resource friendly, of a solution.
If anyone needs any further clarification I would be glad to try to explain it better, but I have tried to make it as easy as I could, but it is a little difficult for even me to understand...
Thanks in advance!
P.S. for those who want the full deal, here is the actual query I am using:
SELECT DISTINCT ageTitle,TIME_FORMAT(ageStartTime,'%I:%i%p') AS ageStartTime,TIME_FORMAT(ageEndTime,'%l:%i%p') AS ageEndTime,sesID,sesTitle,sesDescription,SessionTitleName,sspModerator,perID,perLastName,perFirstNam e,perTitle,perCompany,perPhoto,spoName,spoLink
FROM Agenda, Event, Session, SessionTitle, SessionParticipant, Person
LEFT JOIN Sponsor ON sesspoID=spoID
WHERE seseveID=eveID && seseveID='$eventID' && sesageID=ageID && sesSessionTitleID=SessionTitleID && sspsesID=sesID && sspperID=perID && eveShowAgenda='1' ORDER BY ageStartTime,sesID,sspModerator,perLastName
Basically I have 6 tables A, B, C, D, E, F, G related as follows:
A->B, C->B, D->B, B->E, E->F, G->B
The problem I'm having is how I need the info displayed from these tables...
I have at least one field needed from each of the tables in the returned data, so that requires all the tables, with G being an optional one, so I currently have it under a LEFT JOIN from the rest, and it is working fine. A simplified query for what I am using is
SELECT DISTINCT * FROM A, B, C, D, E, F LEFT JOIN G ON G.BID=BID WHERE AID=B.AID && C.BID=BID && D.BID=BID && B.EID=EID && E.FID=FID && C='value'
I then have 3 loops in PHP as there are multiple needs from those tables
Multiple F records belong to one B record, with multiple B records belonging to 1 A record. Now that much is happening just fine, and I have what I want, except for one thing. The problem is that I need a few additional A records in between the A's I have, meaning I need a few additional records from A that are only from tables A, B, C, rather than all of them, as the rest are. So because they don't need them all, my query doesn't pull them for me. I tried playing with further LEFT JOINs but that just made a mess of it as it returned a ton more records than I need? Now I realize that perhaps subqueries would make this much easier, but I am limited because the server this needs to run on only has MySQL 3.23, and my test server has 4.02 or something, so that doesn't suppport them either.
If there is not a way to pull the required data from that single query, then the only other way I can think of doing it is to pull my primary list from A,B,C and then in the primary outer while loop run the smaller query each time through the loop. But that would take me from 1 db query hit per page to about 20+ queries against the DB, which just doesn't seem like that elegant, or resource friendly, of a solution.
If anyone needs any further clarification I would be glad to try to explain it better, but I have tried to make it as easy as I could, but it is a little difficult for even me to understand...
Thanks in advance!
P.S. for those who want the full deal, here is the actual query I am using:
SELECT DISTINCT ageTitle,TIME_FORMAT(ageStartTime,'%I:%i%p') AS ageStartTime,TIME_FORMAT(ageEndTime,'%l:%i%p') AS ageEndTime,sesID,sesTitle,sesDescription,SessionTitleName,sspModerator,perID,perLastName,perFirstNam e,perTitle,perCompany,perPhoto,spoName,spoLink
FROM Agenda, Event, Session, SessionTitle, SessionParticipant, Person
LEFT JOIN Sponsor ON sesspoID=spoID
WHERE seseveID=eveID && seseveID='$eventID' && sesageID=ageID && sesSessionTitleID=SessionTitleID && sspsesID=sesID && sspperID=perID && eveShowAgenda='1' ORDER BY ageStartTime,sesID,sspModerator,perLastName