[英]Syntax Error in SQL?? 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'
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
它说:
[Err] 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
编辑#2:
我看了你的例子。 愚蠢的我。 谢谢。
您有 2 个WHERE
子句,您需要将第二个WHERE
替换为AND
或OR
。
编辑:就像 ypercube 指出的那样,您在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
编辑2:
WHERE
子句采用 boolean 表达式。 每个查询只能有一个WHERE
子句。
如果要连接 2 个表达式,则必须使用OR
或AND
等。您不需要编写另一个WHERE
子句。 这一切都集中在一个WHERE
中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.