In a query I am using I am creating a temporary table. This is the query:
SELECT u1.url,u1.id,u1.domain FROM urls u1 JOIN
(create new table here) u2 ON u1.id = u2.url_id
GROUP BY u1.domain;
And right before this query I lock two tables:
LOCK TABLES urls WRITE, ips WRITE;
However, mysql gives me this error when I run my script:
Table 'u1' was not locked with LOCK TABLES
So can someone help me understand what I am doing wrong here? I don’t think I can declare u2 ahead of time, because it’s not really made yet.
I found the solution here:
Essentially if you’re going to reference a table with an alias after a lock statement, you need to lock it with an alias.