I'm trying to update a column in visitors
. I'm also using a sub select statement for the SET
part of the update query.
UPDATE
visitors AS v
SET
v.IsFirstVisit = (SELECT COUNT(*) FROM visitors AS v2 WHERE ..... LIMIT 1)
However, mySQL returns this error message
#1093 - You can't specify target table 'v' for update in FROM clause
I have no clue why I can't access the 'v' object within the inner select statement. I also don't want to use multiple statements as this would cause a performance issue.
Question: How can I use the 'v' object within the inner select?
Update: This is the entire query
UPDATE
visitors AS v
SET
IsFirstVisit = (SELECT Count(*) FROM visitors AS v2 WHERE v2.VisitorId < v.VisitorId AND v2.IP = v.IP AND v2.DateTime > v.DateTime [TODO:SUBTRACT30MINUTES] LIMIT 1)
WHERE
VisitorId = "991"