Forum Moderators: open

Message Too Old, No Replies

MySql - Select into. or something

Need to "insert into" using select

         

Demaestro

7:41 pm on Oct 27, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hello,

Just inherited a DB in MySQL 5.0.27-standard and I am normalizing it and removing some of the duplicate data.

I have two tables

parking
parker_id ¦ fname ¦ lanme ¦ recordedon ¦ andSoOn..

parker_has_visit
parker_id ¦ visit_timestamp

I want to move some of the data from the parking table into the parker_has_visit table

I am trying this but can't get it right... is this possible?

insert into parker_has_visit
(parker_id, visit_timestamp)
values
(select parker_id, recorded_on from parking);

Trying to get the parker_id and recorded_on from the parking table into the parker_has_visit table.

ZydoSEO

10:44 pm on Oct 27, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I believe the syntax is more like

INSERT INTO parker_has_visit (parker_id, visit_timestamp)
SELECT parker_id, recorded_on FROM parking

You don't need a VALUES clause and don't need parens around the SELECT in most DBs.

Demaestro

4:02 pm on Oct 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Zy thanks... I almost wrote an import routine.

I don't know why I thought I needed "select into" but that is what I was searching for....

Worked perfect.