I wanted to write additional query to phpbb3 karma mod which checks that a user can't give karma to same person before he hasn't given karma to 3 other persons. But i'm receiving error in my SQL syntax...
I checked this and this link and query i've written looks as follow
SELECT *
FROM phpbb_karma AS out
WHERE out.poster_id = 134
AND out.poster_id
NOT IN
(SELECT k.karma_id, k.user_id, k.poster_id
FROM phpbb_karma AS k
WHERE user_id = 108
ORDER BY k.karma_id DESC LIMIT 3)
So my inner query gets the 3 last persons (poster_id
) whom he (user_id
) gave karma. This query alone works but together with my outer query it gives me error
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 'out WHERE out.poster_id = 134 AND out.poster_id NOT IN (SELECT k.karma_id, k.u' at line 2
In my outer query i write that the person who will be receiving karma is 134
and that he must not be present in my inner query result.
What could be wrong with that query? Is the error really in second row?
I wrote the same query with LEFT JOIN, but it gives me same syntax error
SELECT *
FROM phpbb_karma AS out
LEFT JOIN phpbb_karma AS in
ON in.poster_id = out.poster_id
WHERE in.poster_id = 134 AND in.poster_id IS NULL
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 'out LEFT JOIN phpbb_karma AS in ON in.poster_id = out.poster_id WHERE in.poster_' at line 2
MySQL version is MySQL client version: mysqlnd 5.0.7-dev - 091210 - $Revision: 304625 $
but i don't think that the problem is in version, because the LEFT JOIN doesn't work either