VegetaSan
VegetaSan

Reputation: 55

How to insert multiple values into different rows using MySQL?

I have a table MG_DEVICE_GROUP_IN_GEOZONE that has two columns

| deviceGroup_id| geozone_id|
| ------------- | --------- |

I want to insert multiple values to both columns:

I'm tried to use this query:

insert into MG_DEVICE_GROUP_IN_GEOZONE (deviceGroup_id, geozone_id)
values (4525, (select id from MG_GEOZONE where account_id = 114 and zoneType in (0, 1 , 3)));

But I receiving error - "[21000][1242] Subquery returns more than 1 row"

I understand why this error appeared but I can't find the right query to do this. Please help me. Thanks

Upvotes: 0

Views: 61

Answers (1)

Luuk
Luuk

Reputation: 14929

insert into MG_DEVICE_GROUP_IN_GEOZONE (deviceGroup_id, geozone_id)
select 4525,id from MG_GEOZONE where account_id = 114 and zoneType in (0, 1 , 3);

The INSERT statement can be followed by a SELECT statement, which produces the values to be inserted.

Upvotes: 1

Related Questions