我有一个包含两列的表,userID和contentID。基本上,此表用于将特定内容的访问权限分配给特定用户。我有分配给内容A的每个用户的请求也被分配给内容B.那么如何为每个具有此数据的用户ID(userid,[内容B的id])编写一个新行(userid,[内容的id为A])?
好的,我尝试了前两个帖子所说的内容,并将其转换为:
INSERT INTO tbl_courseAccess
(contentid)
SELECT 11 AS Expr1
WHERE (contentid = 6)
并且没有用,所以我不确定我做错了什么,这是我试图使用的:
insert into tbl_contentAccess
(userid, contentid)
select userid, 11
where contentid = 6
好的我找到了一个新的解决方案,不要再担心了,谢谢大家。
答案 0 :(得分:4)
insert into <table>(userid, contentid)
select userid, [content b id] from <table> where contentid = [content a id]))
已更正:打字太快,无法与其他回答者竞争
答案 1 :(得分:0)
insert into [tablename]
(userid, contentid)
select userid, [id of content B]
where contentid = [id of content A]
答案 2 :(得分:0)
insert into your_table(userid, contentid) select userid,
[id of content B] from your_table where contentid = [id of content A])
那应该做的。
答案 3 :(得分:0)
INSERT INTO mytable (userID,contentID)
SELECT userID,[id of content B] FROM mytable
WHERE content = [id of content A];