sparecycle sparecycle - 3 months ago 7
MySQL Question

MySQL INSERT statement for inserting dynamic and static values

I would like run an INSERT statement to update a MySQL table with two values: The first value is pulled from a SELECT statement on a single column in another table. The second value I would like to be static.

Here is a generic example of what I'm working with:

INSERT INTO employee(id,salary) SELECT id,salary FROM contractor;

However, I would like salary to be a fixed, static value. We'll use '50000' as that static value. So here is a rough version of what I think the final statement would look like:

INSERT INTO employee(id,salary) SELECT id FROM contractor, '50000';

Am I on the right path with this? Thanks.


You can do this way (the resulting value must be in select clause)

INSERT INTO employee(id,salary) SELECT id, 5000 FROM contractor;