我有一个复杂的查询,在添加一行之前它工作正常: 工作查询:
$query = "SELECT SQL_CALC_FOUND_ROWS *
FROM realestate
INNER JOIN users ON id_user = users.id
LEFT JOIN pic ON id_realestate = realestate.id
group by realestate.id
ORDER BY {$order}
LIMIT 0 , 10";
$order
的值为 date DESC
再添加一行后,查询如下:
$query = "SELECT SQL_CALC_FOUND_ROWS *
FROM realestate
{$place}
INNER JOIN users ON id_user = users.id
LEFT JOIN pic ON id_realestate = realestate.id
group by realestate.id
ORDER BY {$order}
LIMIT 0 , 10";
$place
具有此值 WHERE address =1
字段名称 address
在其他表中不会重复。
我收到此 mysql
错误:
Database query failed: You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version
for the right syntax to use near
'INNER JOIN users ON id_user = users.id LEFT JOIN pic ON id_realestate = real'
at line 4
最佳答案
JOIN
子句必须位于 before WHERE
子句。您的条款顺序错误。
关于MySQL语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9122693/