I want to import some values (1 column) using only SQL. The query I wrote looks like it should work, but when I enter it in phpMyAdmin, it just resets the SQL form (I had to write it again the first time) and no inserts are performed. Also, there are no error messages.
The target table (contact) has the same structure as the temporary one with some extra fields.
create temporary table import(
id int,
postalcode varchar(255)
);
insert into import values
(1,'city1'),
(2,'city2'),
...
;
insert into contact(city) (
select postalcode from import
inner join contact on contact.id=import.id
)
where contact.id=import.id
I added the inner join clause because the query couldn’t find the contact.id column in the where clause. Is this the right approach for this case?
The correct solution turned out to be:
View on SQL Fiddle.
This is awesome and will save so much time on writing back-end scripts for import.