I have a PHP form that uses several select boxes that are populated by lookup tables. In an effort to reduce the number of queries per page, I'm trying to find a way to create a cartesian product that would output the results like:
-----------------------------------------------------------------
| City | State | SchoolDistrict |
-----------------------------------------------------------------
| Adamsville | AL | Adamsville Public Schools |
| Brownsville | AK | Baker-Cow USD |
| Cowtown | AR | NULL |
| NULL | AZ | NULL |
| NULL | CA | NULL |
-----------------------------------------------------------------
Then I could just loop through each field until it found null (or 0-length string).
When I tried:
SELECT a.City, b.State, c.SchoolDistrict FROM Cities a, State b, SchoolDistricts c
it returns:
-----------------------------------------------------------------
| City | State | SchoolDistrict |
-----------------------------------------------------------------
| Adamsville | AL | Adamsville Public Schools |
| Brownsville | AK | Baker-Cow USD |
| Cowtown | AR | Baker-Cow USD |
| Cowtown | AZ | Baker-Cow USD |
| Cowtown | CA | Baker-Cow USD |
-----------------------------------------------------------------
Any ideas?