Pages

Search This Blog

Wednesday, November 9, 2011

MYSQL - IF NOT EXISTS ... INSERT INTO

Database MYSQL - tried IF NOT EXISTS ... INSERT INTO but not working.

IF NOT EXISTS (SELECT * FROM tblabc WHERE id = 10547) THEN
INSERT INTO tblabc
(a, b, c)
SELECT a , b, c
FROM tblabc WHERE id = 10547;

END IF;


Finally, this work

INSERT INTO tblabc
(a, b, c)
SELECT a , b, c
FROM tblabc WHERE id = 10547
AND NOT EXISTS (SELECT * 
FROM tblabc WHERE id = 10547);

1 comment:

Anonymous said...

i really appreciate it!!...