choky7
choky7

Reputation: 33

MYSQL SQL Statement which insert many rows

I want to put contents to notice Database user level > 1;

so I tried this Statement

insert into test4 (id, content) values (
    (select user_id from account where user_rank>=0), 
    'alert'
);

But it keep saying Subquery returns more than 1 row.

Is it impossible to put many rows in one statement?

Thank you.

Upvotes: 0

Views: 28

Answers (2)

RusArtM
RusArtM

Reputation: 1300

Try this

INSERT INTO test4 (id, content)
VALUES SELECT user_id, 'alert' FROM account WHERE user_rank >= 0;

Upvotes: 0

GMB
GMB

Reputation: 222482

values() expects a tuple of values that represent just one row, but your subquery returns multiple rows, hence the error that you are getting.

Instead, you can use the insert ... select syntax, with a fixed literal value as second column:

insert into test4 (id, content)
select user_id, 'alert' from account where user_rank > °

Upvotes: 1

Related Questions