【发布时间】:2014-03-25 17:46:55
【问题描述】:
重新设计数据库布局,我遇到了障碍:
现在名为 Items_Old 的原始表具有以下 3 列的重要性:
Name | Width | Length
此后我创建了一个名为ItemSizes 的新表:
ID | Width | Length
最后一个叫Items:
Name | SizeID
我想弄清楚如何从ItemSizes 表中选择 SizeID 到Items 表中
where Items_Old.Name = Items.Name and Items_Old.Width = ItemSizes.Width
AND Items_Old.Length = ItemSizes.Length
我已经获得了 SizeID 和 Items_Old.Name 的列表,其中包含以下内容:
Select IST.ID , Old.Name
From ItemSizes AS IST, Items_Old AS Old
Where IST.Width = Old.Width
And IST.Length = Old.Length
但是当我尝试类似的东西时:
Insert Into Items
(SizeID)
Select IST.ID , Old.Name
From ItemSizes AS IST, Items_Old AS Old
Where IST.Width = Old.Width
And IST.Length = Old.Length
Where Items.Name = Info.Name
由于第二个我也尝试过的地方而出现语法错误
Insert Into Items
(SizeID)
(Select IST.ID , Old.Name
From ItemSizes AS IST, Items_Old AS Old
Where IST.Width = Old.Width
And IST.Length = Old.Length) As Info
Where Items.Name = Info.Name
但出现错误near "("
【问题讨论】:
-
我猜你已经在
Items表的Name列中有一些值,并且你想更新SizeID列。是吗? -
@BhupeshC 是的,我已经意识到我不想插入并且我确实想更新,我现在一直在尝试找出更新的 With 语法。
-
哪个是你的数据库,Oracle、SQL Server、MySQL等?
-
@BhupeshC 在标签中,是
SQLite3
标签: sql join sqlite database-administration insert-select