MySQL之间的查询返回多余的结果

0 php mysql

SELECT webcal_entry.cal_id, webcal_entry.cal_name , webcal_entry.cal_priority,
webcal_entry.cal_date , webcal_entry.cal_time , webcal_entry_user.cal_status,
webcal_entry.cal_create_by , webcal_entry.cal_access, webcal_entry.cal_duration ,
webcal_entry.cal_description , webcal_entry_user.cal_category 
FROM webcal_entry, webcal_entry_user
WHERE webcal_entry.cal_date BETWEEN '20090601' AND '20090631'
Run Code Online (Sandbox Code Playgroud)

当我执行该查询时,php会抛出:

mysql_query(): unable to save result set
MySQL client ran out of memory
Run Code Online (Sandbox Code Playgroud)

当我限制结果时,我发现它正在回收大约280万个结果.该表有7,241行.

我意识到我可以使用LIKE,但我真的不想走那条路.

谢谢你的帮助!

Joh*_*ica 5

您正在加入子句中的webcal_entrywebcal_entry_user表,FROM但是没有任何JOIN ONWHERE条件限制webcal_entry_user返回哪些行.结果将是两个表的笛卡尔积,这基本上意味着您将返回webcal_entry具有有效的每一行cal_date,乘以webcal_entry_user表中的行数.

换句话说,如果你webcal_entry_user有400行,你将获得400*7241 = 280万行!哎呀!