MySQL: SQL query to duplicate data in one table

I have a say table table1(id, col2, col3), and I want to duplicate all the data id 1, but with different idsay 11(the identifier is not an automatically generated column). I wrote the following sql query that does not work for me (giving a syntax error):

INSERT INTO table1(
id,
col2,
col3
)
VALUES (

SELECT 11 , col2, col3
FROM table1 WHERE id=1
)
+5
source share
4 answers

Do not use the keyword "VALUES"

INSERT INTO table1(
id,
col2,
col3
)


SELECT 11 , col2, col3
FROM table1
WHERE id = 1

EDIT:

Check if you are working with the names of the correct columns:

DESC table1;
+8
source

Try the following:

INSERT INTO table1(
id,
col2,
col3
)
SELECT 11 , col2, col3
FROM table1
WHERE table1.id = 1

OR if you need something else like this:

INSERT INTO table1(id, col2, col3)
SELECT (SELECT MAX(id) FROM table1) + 1 , col2, col3
FROM table1
+3
source

INSERT INTO ... SELECT WHERE id = 1:

INSERT INTO table1(id, col2, col3)
SELECT '1' + id , col2, col3
FROM table1
WHERE id = 1
+2

INSERT VALUES SELECT, .

INSERT INTO table1( id, col2, col3 ) 
SELECT 11 , col2, col3 
FROM table1 
WHERE id = 1 
+2

All Articles