Forum Moderators: open

Message Too Old, No Replies

new to mysql

         

jachamp

5:24 am on Mar 14, 2009 (gmt 0)

10+ Year Member



Hi,

I have a basic question about a MySQL db. If I have a table of names, numbers and images (those are the column names) and I want to insert that same data into a 22 column table as an autofill so that I don't have to hand type each name into the db, which command do I use?

I've tried INSERT INTO and I've tried join-ing...and those have generated errors.

How do I get the values from three columns into the new table? BTW--I used the same names for these columns and even put them in the same order in phpmyadmin

Thanks all...I do not need someone to do the work for me but just to point me in the right direction.

rocknbil

6:32 am on Mar 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



create table test1 (id int(11) primary key auto_increment, fname varchar(255), lname varchar(255));

create table test2 (id int(11) primary key auto_increment, fname varchar(255), lname varchar(255));

insert into test1 (fname,lname) values('John','Smith');
insert into test1 (fname,lname) values('Mary','Jones');
insert into test1 (fname,lname) values('Seymour','Butz');

insert into test2(select * from test1);

select * from test2;
And you know the result. :-)

Specific cols:

insert into test2 (fname,lname) (select fname,lname from test1);

jachamp

1:55 pm on Mar 14, 2009 (gmt 0)

10+ Year Member



Ah..okay..thanks. So either way I am going to have to copy/paste or retype all the names anyway. Gotcha...

Thanks..I'll try it your way to learn some more.

jachamp

2:42 pm on Mar 14, 2009 (gmt 0)

10+ Year Member



ha...okay...that produced an unexpected result. this is for an amateur baseball team to keep stats throughout the season...

anyhow...i entered the first column and it went well...the second insert however..created new rows with the firstname and lastname columns.

and if i try to enter all three columns at one time i get an error.

jachamp

2:52 pm on Mar 14, 2009 (gmt 0)

10+ Year Member



ha! i got it to work!

I did an insert and removed the () from the SELECT portion and used this query :

INSERT INTO stats ('number', 'firstname', 'lastname') SELECT 'number', 'firstname', 'lastname' FROM players