Domanda

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?

È stato utile?

Soluzione

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

Altri suggerimenti

From the manual :

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top