Skip to content
Advertisement

MySQL INSERT INTO … VALUES and SELECT

Is there a way to insert pre-set values and values I get from a select-query? For example:

I have the value of “A string” and the number 5, but I’ve to find the [int] value from a select like this:

that gives me that id to put inside table1.

How to merge this into one statement?

Advertisement

Answer

Use an insert ... select query, and put the known values in the select:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement