1

Is it possible to insert a new row in mysql, with just one value copied from the database, and the other values provided directly?

I want to be able to do something like this:

INSERT INTO table (col1,col2,col3) VALUES(val1,val2,(SELECT col3 FROM table WHERE col1=val11 AND col2=val22))

Any ideas?

Tiddo
  • 6,331
  • 6
  • 52
  • 85

2 Answers2

1

If you specify the values directly within the query you could go with.

INSERT INTO table (col1,col2,col3) SELECT 'val1', 'val2', col3 FROM table WHERE col1='val11' AND col2='val22';
DanielB
  • 19,910
  • 2
  • 44
  • 50
0
insert into t1 (col1,col2,col3) VALUES ('hello','world',(select col2 from t2 where id=1));

Query OK, 1 row affected (0.00 sec)

Gryphius
  • 75,626
  • 6
  • 48
  • 54