Reputation: 3
I have this query and appearently it's faulty?
I'm trying to join fices
with mems
so I can have the ficeID
along with all the results from mems
(These queries work individually). What am I doing wrong?
SELECT *
FROM mems
WHERE deleted <> -1
ORDER BY sort_mems
LEFT JOIN SELECT ficeID
FROM fices
Result:
#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
Upvotes: 0
Views: 111
Reputation: 3179
JOIN
clause after ORDER BY
. You should place it in FROM
.LEFT JOIN
Also, I suggest you surround you temp tables with brackets:
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;
Upvotes: 1
Reputation: 15450
Yes, you have the LEFT JOIN
in the wrong spot (it should go after your FROM
clause, and you also seem to be missing a join criteria (the ON
part, this tells the database how these tables are related):
SELECT *
FROM mems m
LEFT JOIN fices f
ON m.??? = f.???
WHERE deleted <> -1
ORDER BY sort_mems
Upvotes: 1