Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple insert query help

Status
Not open for further replies.

elentz

Technical User
Jan 9, 2007
81
US
i know this should be very simple, and I have gone to the MySql KB and I just for some reason can't wrap my head around this. I have two tables table 1, has many fields, table 2 has fewer fields. The two tables have fields that are the same, (name, type, etc..) There is on link between them. I want to take all the fields from the larger table and insert ALL the records into the table 2 in the same fields. Can someone show me the way??

Thanks!
 

Code:
INSERT INTO tb2 (name, type) SELECT name, type FROM tbl1

Add any conditions you want, i.e.
Code:
INSERT INTO tb2 (name, type) SELECT name, type FROM tbl1
WHERE name = 'FRED'



------------------------------------
There's no place like 127.0.0.1
------------------------------------
 
Thanks for the help!!

I need to copy or insert about 25 fields. I tried :

insert into tb2 (name1),(name2) Select name1 ,name2 from TB1

And I got an error. When I only entered one field it worked ok. What else can I try?

Thanks
 
Change

Code:
insert into tb2 (name1),(name2)  Select name1 ,name2 from TB1

TO

Code:
insert into tb2 (name1, name2) select name1, name2 from tb1


------------------------------------
There's no place like 127.0.0.1
------------------------------------
 
Thanks AP81!!

That worked just as I needed it.

Have a great day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top