SELECT `bio_community_events`.`id`,
`bio_community_events`.`begin_on`,
`bio_community_events`.`name`
FROM `bio_community_events`
JOIN `bio_contacts`
ON (`bio_contacts`.`contact_id` = `bio_community_events`.`user_id`)
JOIN `bio_community_groups`
ON (`bio_community_groups`.`id` = `bio_community_events`.`group_id`)
WHERE `bio_contacts`.`user_id` = '33'
WHERE `bio_community_events`.`group_id` = '1'
LIMIT 10
UNION ALL
SELECT `bio_community_events`.`id`,
`bio_community_events`.`begin_on`,
`bio_community_events`.`name`
FROM `bio_community_events`
JOIN `bio_contacts`
ON (`bio_contacts`.`user_id` = `bio_community_events`.`user_id`)
JOIN `bio_community_groups`
ON (`bio_community_groups`.`id` = `bio_community_events`.`group_id`)
WHERE `bio_contacts`.`contact_id` = '33'
WHERE `bio_community_events`.`group_id` = '1'
LIMIT 10
Run Code Online (Sandbox Code Playgroud)
它说:
[错误] 1064 - 您的SQL语法有错误; 检查与MySQL服务器版本对应的手册,以便在'WHERE附近使用正确的语法
bio_community_events.group_id='1'
我找不到语法错误!
编辑:
我把所有包装成括号并添加"AND WHERE".不工作......仍然是同样的错误.
新查询:
SELECT `bio_community_events`.`id`,
`bio_community_events`.`begin_on`,
`bio_community_events`.`name`
FROM `bio_community_events`
JOIN `bio_contacts`
ON (`bio_contacts`.`contact_id` = `bio_community_events`.`user_id`)
JOIN `bio_community_groups`
ON (`bio_community_groups`.`id` = `bio_community_events`.`group_id`)
WHERE (`bio_contacts`.`user_id` = '33')
AND WHERE (`bio_community_events`.`group_id` = '1')
LIMIT 10
UNION ALL
SELECT `bio_community_events`.`id`,
`bio_community_events`.`begin_on`,
`bio_community_events`.`name`
FROM `bio_community_events`
JOIN `bio_contacts`
ON (`bio_contacts`.`user_id` = `bio_community_events`.`user_id`)
JOIN `bio_community_groups`
ON (`bio_community_groups`.`id` = `bio_community_events`.`group_id`)
WHERE (`bio_contacts`.`contact_id` = '33')
AND WHERE (`bio_community_events`.`group_id` = '1')
LIMIT 10
Run Code Online (Sandbox Code Playgroud)
编辑#2:
我看了你的例子.愚蠢的我!谢谢.
你有2个WHERE条款,你需要WHERE用AND或替换你的第二个OR.
编辑:像ypercube指出的那样,你在-clause的两个子查询中都有错误UNION.
例如:
SELECT `bio_community_events`.`id`,
`bio_community_events`.`begin_on`,
`bio_community_events`.`name`
FROM `bio_community_events`
JOIN `bio_contacts`
ON (`bio_contacts`.`user_id` = `bio_community_events`.`user_id`)
JOIN `bio_community_groups`
ON (`bio_community_groups`.`id` = `bio_community_events`.`group_id`)
WHERE `bio_contacts`.`contact_id` = '33'
AND `bio_community_events`.`group_id` = '1'
LIMIT 10
Run Code Online (Sandbox Code Playgroud)
编辑2:
甲WHERE子句需要一个布尔表达式.WHERE每个查询只能有一个子句.
如果要连接2个表达式,则必须使用OR或AND等.您不需要编写另一个WHERE子句.这一切都融为一体WHERE.