Home > Net >  How to select a list of data in MySQL and insert with one Query with SQL Language
How to select a list of data in MySQL and insert with one Query with SQL Language

Time:07-29

I have a Select Statement that fetches more than 1 data

set @name := select name from users;

Now I want to insert all of them with one Query

for example

insert into users2 (name , created) Values (@name , NOW())

it returns this error

Error Code: 1242
Subquery returns more than 1 row

is there any way to do this without a loop?

CodePudding user response:

The syntax must be like this

insert into users2 (name , created)
select name, NOW()  from users

CodePudding user response:

Try this

insert into users2 (name , created) 
 select name, NOW() from users;
  • Related