SQL语法错误(访问冲突:1064)

时间:2015-08-17 12:21:11

标签: mysql left-join

这是一个SQL查询:

SELECT COUNT(*) FROM `actors` `t` WHERE company_name LIKE "%test%" 
LEFT JOIN `actors_adresses` ON `actors`.id = `actors_adresses`.actor
AND `actors_adresses`.adress LIKE "%test2%"

请帮我找错误=(

3 个答案:

答案 0 :(得分:1)

您的语法不正确。永远不会来自和加入

请参阅https://dev.mysql.com/doc/refman/5.0/en/select.html

答案 1 :(得分:1)

按以下方式尝试 -

SELECT COUNT(*) FROM `actors` `t` 
LEFT JOIN `actors_adresses` a ON t.id = a.actor
WHERE t.company_name LIKE "%test%" 
AND a.adress LIKE "%test2%"

答案 2 :(得分:1)

WHERE应该在每个语法JOIN之后出现。您的查询应该是

SELECT COUNT(*) 
FROM `actors` 
LEFT JOIN `actors_adresses` ON `actors`.id = `actors_adresses`.actor
// You can leave this condition here as JOIN condition
AND `actors_adresses`.adress LIKE '%test2%' 
WHERE `actors`.company_name LIKE '%test%'