I'm trying to do it
- Get all blog posts with the table name.
- Copy them to a temporary database
- Edit the language field of this temporary table entry
- Insert into blog table
And I try it like this:
CREATE TEMPORARY TABLE tmptable SELECT * FROM blogs WHERE lan = 2; UPDATE tmptable SET lan = 1; INSERT INTO blogs SELECT * FROM tmptable; dump database tmptable;
But from the corsa I get a duplicate key error ...
How can I prevent this?
-Edit -
I TRIED:
CREATE TEMPORARY TABLE tmptable SELECT * FROM blogs WHERE lan = 2; UPDATE tmptable SET lan = 1; ALTER TABLE tmptable DROP id; INSERT INTO blogs SELECT * FROM tmptable; dump database tmptable;
But then Column count doesn't match value count at row 1
-Edit -
I believe this will work (And that was because I know how many records exist)
CREATE TEMPORARY TABLE tmptable SELECT * FROM blogs WHERE lan = 2; UPDATE tmptable SET lan = 1; UPDATE tmptable SET id = id + 1000; INSERT INTO blogs SELECT * FROM tmptable;
But how can I do it right? (just set the following auto-increment value for the primary key (id) (without PHP / the same))
-Edit -
maybe something like this ???
CREATE TEMPORARY TABLE tmptable SELECT * FROM blogs WHERE lan = 2; UPDATE tmptable SET lan = 1; UPDATE tmptable SET id = id + (SELECT id FROM blogs ORDER BY id DESC LIMIT 1); INSERT INTO blogs SELECT * FROM tmptable;
source share