• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 499
  • Last Modified:

SQL Insert into one table from another

I need select the RecID field from one table then do an insert into another table fore each row that was found.  Any examples of that?

My select will be:
Select RecID from Meta where username = 'jdoe'

I want to loop through those then do this insert:
Insert into Publishers (fkRecID, PRO_Name) values (RecID_From_Loop, 'XYZ')
0
JT_SIRO
Asked:
JT_SIRO
  • 2
1 Solution
 
jmnfCommented:
INSERT INTO Publishers (fkRecID, PRO_Name)
     VALUES ( (SELECT RecID FROM Meta WHERE username = 'jdoe'), 'XYZ')
0
 
jmnfCommented:
I think last one does not work, maybe this one will.

INSERT INTO Publishers (fkRecID, PRO_Name)
     SELECT RecID, 'XYZ' FROM Meta WHERE username = 'jdoe';

Open in new window

0
 
Ephraim WangoyaCommented:


Insert into Publishers (fkRecID, PRO_Name)
select RecID_From_Loop, 'XYZ'
from Meta where username = 'jdoe'
0
 
Aaron TomoskyTechnology ConsultantCommented:
I think ewangoya is correct. No "values" when using an insert select.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now