Вопрос

I tried the following query:

mysql> INSERT INTO tm_visitor (VDT,VID, NAME, CONTACT) values(REPLACE(LE
FT(NOW(), 10), '-', ''),(SELECT LPAD(COALESCE(MAX(VID) + 1, 000001), 6, '0') FRO
M tm_visitor),'yatin','9876543120');

but I get the following error.

ERROR 1093 (HY000): You can't specify target table 'tm_visitor' for update in FROM clause`

What is going wrong and how do I fix it?

Это было полезно?

Решение

INSERT INTO tm_visitor (VDT,VID, NAME, CONTACT) 
SELECT REPLACE(LEFT(NOW(), 10), '-', ''), 
   LPAD(COALESCE(MAX(VID) + 1, 000001), 6, '0'), 
   'yatin','9876543120' 
FROM tm_visitor

Другие советы

From the manual :

This error occurs in cases […] which attempts to modify a table and select from the same table in the subquery

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top