我有一个 PHP 表单,它使用了几个由查找表填充的选择框。为了减少每页的查询数量,我试图找到一种方法来创建一个笛卡尔积,该积将输出如下结果:
-----------------------------------------------------------------
| City | State | SchoolDistrict |
-----------------------------------------------------------------
| Adamsville | AL | Adamsville Public Schools |
| Brownsville | AK | Baker-Cow USD |
| Cowtown | AR | NULL |
| NULL | AZ | NULL |
| NULL | CA | NULL |
-----------------------------------------------------------------
然后我可以遍历每个字段,直到找到 null(或 0 长度字符串)。
当我尝试时:
SELECT a.City, b.State, c.SchoolDistrict FROM Cities a, State b, SchoolDistricts c
它返回:
-----------------------------------------------------------------
| 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 |
-----------------------------------------------------------------
有任何想法吗?