想用mysql存储实现下面的插入。
insert into group_member(group_id,member_id,role,joined_at) values (59,select user_id from department_user_new where department_id !=1 and user_id not in(select member_id from group_member where group_id=59),3,now());
这个是从另一张表查询得到的结果,用上面的语句不能成功插入,用存储过程怎么写呢?
select user_id from department_user_new where department_id !=1 and user_id not in(select member_id from group_member where group_id=59)
------解决方案--------------------------------------------------------
那LZ需要对where 条件再过滤一下。保证只有一条记录。不然,SP也不好用吧。
where department_id !=1 and user_id not in(select member_id from group_member where group_id=59
------解决方案--------------------------------------------------------
select user_id from department_user_new where department_id !=1 and user_id not in(select member_id from group_member where group_id=59)
这是多条的话,插入肯定有错了