1

insert into select同じテーブルの2つの異なる行からデータを選択する必要があることを除いて、テーブル1からテーブル2に行をコピーするために使用しています。これはどのように行うことができますか?

表1

"id"    "name"      "description"   "path"                              "country"   "status"
"1"     "Title 1"   "Description 1" "US > Consumer > Home Applicances"  "US"        "0"
"2"     "Title 2"   "Description 2" "US > Business > Legal Charges"     "UK"        "0"

表 2

"id"    "name"  "description"   "path"  "newId" "newPath"   "country"   "status"

現在の SQL

insert into table2 select null, name, description, path, country, status from table1 where id=1;

2つを一気にやろうとする

$currentId = 1;
$newId = 2;

// This'll update columns name, description, path, country, status
insert into table2 select null, name, description, path, country, status from table1 where id=$currentId;

// This'll need to update newId, newPath same row
insert into table2 newId, newPath from table1 where id=$newId;

//Trying to achiev    
insert into table2 select null, name, description, path, country, status from table1 where id=$currentId, insert into table2 //newId, newPath  select id, path from table1 where id=$newId;
4

1 に答える 1