Reputation: 61
I'm currently in the process of merging two tables in my DB. I'm trying to use this code:
INSERT INTO starinformation( pageX, pageY )
SELECT pageX, pageY
FROM starmaptopdown
WHERE starID = starinformation.starID
but the code isn't working. The query is exucuting saying that all the tables were effected, but the information was not placed into the database/
Upvotes: 1
Views: 172
Reputation: 1269823
The select
query on an insert
cannot be correlated with the table being inserted. I'm guessing that you want an update
and not an insert
. The exact format for this varies by database. In MySQL, the syntax is:
update startinformation i join
starmaptopdown md
on i.startID = md.startID
set i.pageX = md.pageX,
i.pageY = md.pageY;
In SQL Server and Postgres:
update startinformation
set pageX = md.pageX,
pageY = md.pageY
from startinformation join
starmaptopdown md
on i.startID = md.startID;
Upvotes: 3