I am trying to write an sql script to do a bulk insert. I need it to add the users that are managers into the manager's group. I tried to write it like this
INSERT INTO group_member (group_id, user_id) VALUES ((SELECT group_id FROM user_group WHERE group_name = 'Manager') , (SELECT user_id
FROM user WHERE manager=1 and user_status = 1));
but I am getting this error
Subquery returns more than 1 row
I understand the error but am not sure how to work around it so that I do not miss any users.
When run there can be 0 to many managers, not sure if that will make a difference.
sql version: 5.6.27
CREATE TABLE user_group(
group_id INT(11) NOT NULL AUTO_INCREMENT,
group_name VARCHAR(128) NULL DEFAULT NULL,
PRIMARY KEY (group_id)
);
CREATE TABLE user (
user_id INT(11) NOT NULL AUTO_INCREMENT,
user_name VARCHAR(128) NULL DEFAULT NULL,
manager INT(11) NOT NULL
user_status INT(11) NOT NULL
PRIMARY KEY (user_id)
);
CREATE TABLE group_member (
group_id INT(11) NOT NULL,
user_id INT(11) NOT NULL,
PRIMARY KEY (group_id, user_id)
);