这是我的搜索查询,它发出了一个参数错误
我需要做些什么来纠正它。基本上,我需要把这两个表放在一起,并在start
日期之前提取出两个表中接下来的5个事件。您还会注意到,每个表中的最后一个字段彼此不同。
$CEsql = mysql_query("
SELECT id, title, start, end, allDay
FROM calendar
WHERE mem_id='$logOptions_id'
AND start >= DATE_SUB( CURDATE( ) ,INTERVAL 0 MONTH )
UNION ALL
SELECT id, title, start, end, allDay
FROM team_calendar
WHERE team_id IN ($team_array)
AND start >= DATE_SUB( CURDATE( ) ,INTERVAL 0 MONTH )
ORDER BY start ASC LIMIT 5");
我使用的是MYSQL 5.0和PHP。
更新
mysql_error
显示:
1267:非法混合"UNION"行动的排序规则
请检查WHERE子句。使用mem_id而不是id2。id2只是别名,而不是字段名。
$CEsql = mysql_query("
SELECT id, title, start, end, allDay, mem_id as id2
FROM calendar
WHERE mem_id='$logOptions_id'
AND start >= DATE_SUB( CURDATE( ) ,INTERVAL 0 MONTH )
UNION ALL
SELECT id, title, start, end, allDay, team_id as id2
FROM team_calendar
WHERE team_id IN ($team_array)
AND start >= DATE_SUB( CURDATE( ) ,INTERVAL 0 MONTH )
ORDER BY start ASC LIMIT 5");
为两个表运行SHOW CREATE TABLE语句。按照Leap Bun的建议,查找两个表之间的差异,检查字符集和排序规则。然后,您可以更改字段字符集/排序规则,或者只尝试在SELECT查询中使用COLLATE子句。类似这样的东西-
SELECT id, title, start, end, allDay
FROM calendar
WHERE mem_id='$logOptions_id'
AND start >= DATE_SUB( CURDATE( ) ,INTERVAL 0 MONTH )
UNION ALL
SELECT id,
title COLLATE collation_name AS title, -- write your collation here
start, end, allDay
FROM team_calendar
WHERE team_id IN (1,2)
AND start >= DATE_SUB( CURDATE( ) ,INTERVAL 0 MONTH )
ORDER BY start ASC LIMIT 5