当前位置: 代码迷 >> J2SE >> mysql存储过程,循环安插接
  详细解决方案

mysql存储过程,循环安插接

热度:7502   发布时间:2013-02-25 00:00:00.0
mysql存储过程,循环插入接
想用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)
这是多条的话,插入肯定有错了
  相关解决方案