tags:

views:

163

answers:

4

I have a table with two columns, userID and contentID. Basically this table is used to assign access to certain content to specific users. I have the request of every user that is assigned to content A also be assigned to content B. So how would I write a new row with this data (userid, [id of content B]) for each row that has (userid, [id of content A])?

OK I tried what the top two posts said and it converted it to:

INSERT INTO tbl_courseAccess
                      (contentid)
SELECT     11 AS Expr1
WHERE     (contentid = 6)

and didn't work, so I'm not sure what I did wrong, here is what I tried to use:

insert into tbl_contentAccess
(userid, contentid)
select userid, 11
where contentid = 6

OK I found a new solution, don't worry about this anymore, thanks everyone.

+3  A: 
insert into <table>(userid, contentid)
select userid, [content b id] from <table> where contentid = [content a id]))

Corrected: Typing too fast to race you other answerers

orthod0ks
A: 
insert into [tablename]
(userid, contentid)
select userid, [id of content B]
where contentid = [id of content A]
jhale
need the 'from' or it fails
shogun
A: 
    insert into your_table(userid, contentid) select userid, 
[id of content B] from your_table where contentid = [id of content A])

That should do the job.

david a.
A: 
INSERT INTO mytable (userID,contentID) 
  SELECT userID,[id of content B] FROM mytable 
    WHERE content = [id of content A];
Dave Webb