when you use lock tables, you need to lock all tables in the query. When you use a subquery, it creates a table. and you do not block it. because of this you get an error.
link: http://dev.mysql.com/doc/refman/5.0/en/lock-tables.html
give an alias to the internal table
test sample:
lock tables products as p1 write, products as p2 write ; select product_id from products as p1 where product_id not in ( select product_id from products p2 where product_id in (1,2) )
And probably you need to do this:
lock tables radcheck as r1 write, radcheck as r2 write ; SELECT * FROM radcheck r1 WHERE id NOT IN ( SELECT id FROM ( SELECT id FROM radcheck r2 WHERE attribute = 'Password' GROUP BY UserName HAVING COUNT(*) > 1) AS c );
source share