我有一个很大的查询,在我网站的一个页面中有很多内部连接。我想申请一些左外连接限制 1 但如果我把它放到 sql 中会给我错误。
这是我的查询的一小部分不是全部,这个查询只是一部分并且ISN'T FINISH:
SELECT * FROM products
LEFT OUTER JOIN (origins
LEFT OUTER JOIN origin_aliases ON origin_aliases.origin_id = origins.id
AND origin_aliases.language = '$lang'
LEFT OUTER JOIN (diets LEFT OUTER JOIN diet_aliases ON diet_aliases.diet_id = diets.id AND diet_aliases.language = '$lang')
ON origins.diet_id = diets.id)
ON products.origin_id = origins.id
LEFT OUTER JOIN (product_aliases
LEFT OUTER JOIN (users as users1
LEFT OUTER JOIN profiles as profiles1 ON profiles1.user_id = users1.id
LEFT OUTER JOIN user_options as user_options1 ON user_options1.user_id = users1.id
LEFT OUTER JOIN avatars as avatars1 ON avatars1.user_id = users1.id
)
ON product_aliases.user_id =users1.id
LEFT OUTER JOIN (users as users2
LEFT OUTER JOIN profiles as profiles2 ON profiles2.user_id = users2.id
LEFT OUTER JOIN user_options as user_options2 ON user_options2.user_id = users2.id
LEFT OUTER JOIN avatars as avatars2 ON avatars2.user_id = users2.id
)
ON product_aliases.edit_user_id = users2.id)
ON product_aliases.product_id = products.id
......
例如,我想在原点的左外连接中应用限制 1 ON 'products.origin_id'='origins.id'
是可能的吗?我怎样才能做到这一点?我试图在条件限制 1 之后放置,但给我一个错误
语法错误或访问冲突:1064 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册以获取正确的语法