我有这个查询,显然它有问题吗?
我正在尝试与fices
加入mems
,因此我可以将ficeID
以及mems
的所有结果(这些查询单独运行)。我做错了什么?
SELECT *
FROM mems
WHERE deleted <> -1
ORDER BY sort_mems
LEFT JOIN SELECT ficeID
FROM fices
结果:
#1064 - 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 'LEFT JOIN SELECT ficeID FROM offices LIMIT 0, 30' at line 1
答案 0 :(得分:1)
JOIN
之后您有ORDER BY
个子句。您应该将其放在FROM
。LEFT JOIN
另外,我建议你用括号围绕临时表:
SELECT m.*, t1.officeID
FROM members m
LEFT JOIN offices t1
ON m.memberID = t1.memberID
WHERE m.deleted <> -1
ORDER BY m.sort_membername;
答案 1 :(得分:1)
是的,您的LEFT JOIN
位于错误的位置(它应该在您的FROM
子句之后,并且您似乎也错过了加入条件(ON
部分,这告诉数据库这些表是如何相关的):
SELECT *
FROM mems m
LEFT JOIN fices f
ON m.??? = f.???
WHERE deleted <> -1
ORDER BY sort_mems