This is more of an “approach” question, I haven’t gotten to the code yet. But am new to SQL and php and would like to tackle this issue intelligently.
The scenario is as follows:
I have a table called Donations, each of which has exactly one string value in the column called AREA. AREA may have any one of nine predetermined values (Northeast, Northwest, Downtown, etc…).
I also have a table of Volunteers, each of which has specified which regions they are willing to travel to, to help pick-up the donations. For each volunteer, I have 9 columns, each with a 1 or 0, corresponding to the nine areas listed above (NW, NE, DT, etc…)
I would like to run a query, series of queries or php/sql combination where by I can search for all active donations, attain which AREA’s they are in, then query the Volunteers table, and get back a list of email address for only those Volunteers willing to travel to one or more of those areas.
Any help is appreciated. (As an aside, there is no key value shared between these two tables.)
So, I solved this via a totally different method altogether, though I am sure the above methods would have worked.
I created assigned each area a prime number, beginning with 2, 3, 5, etc…Then when a Volunteer registered, it creates a code for them by multiplying those areas they are willing to go to.
I used the same primes for donations and assigned each donation the appropriate prime.
Then I ran this join query, seeing if the Volunteer’s code was evenly divisble by any of the available donations.
$q = “Select Distinct(EMAIL) from PUPS where EXISTS (Select * from Donations where STATUS = ‘ACTIVE’ AND (REGIONCODE Mod AREAPRIME = 0))”;