您好我的情况是用户被分配到多对多关系的项目中。每次我添加新用户时,我希望为他复制现有的分配,换句话说,将他分配给所有项目,其他用户也被分配。目前我复制整个表,然后按如下方式重新插入,但想知道是否可以在一个查询中排序?
# tmp_assignments already exist and have same fields as assignment
truncate tmp_assignments;
INSERT tmp_assignments SELECT * FROM assignments;
# 38 is new user id
insert into assignments (project,user)
select a.project,38
from tmp_assignments as a group by project;