INSERT使用SELECT语句,并在MySQL中同时向结果的每一行添加一个变量值[duplicate]

This question already has an answer here:

I have a table nameValue that has 5 columns (Id,val,firstName,lastName,age). I use a select statement that gives firstName,lastName, age in multiple rows, lets say it returns 5 rows. Id is Auto-Increment. I want to add val to each of the 5 rows returned.

$val=55; INSERT INTO nameValue (val,firstName,lastName,age) VALUES($val, SELECT fName,lName,age FROM nameAge WHERE age<25); something like this where we are insert same variable $val to each of the 5 rows returned by the select statement.

</div>

Thats the wrong way. Try this -

INSERT INTO nameValue (val,firstName,lastName,age)
SELECT $val, fName,lName,age FROM nameAge WHERE age < 25