我花了一上午的时间从头开始学习 SQL,但我很难做到 简单 事情,我什至不知道该怎么称呼它(某种插入连接?)
我有两张看起来像这样的 table ......
Table: ImageIDLookup Table: ImagesTable
ID | ImageID Id | Path
21 | 147 147 | fu
42 | 268 268 | bar
53 | 547 547 | bla
etc... etc...
我要做的就是从 插入“路径”列图片表 表入 ImageID 查找 使用两个表中名为“ImageID”和“Id”的列的表,它们具有匹配的行。
所以 ImageID 查找 table 会变成...
Table: ImageIDLookup
ID | ImageID | Path
21 | 147 | fu
42 | 268 | bar
53 | 547 | bla
etc...
我意识到这是基本的,但是当我没有名称时,我发现很难研究简单的概念。
最佳答案
首先添加一个新列到 ImageIDLookup
:
ALTER TABLE ImageIDLookup ADD COLUMN Path TEXT;
其次,从
ImagesTable
添加路径值至ImageIDLookup
:UPDATE ImageIDLookup
SET Path =
(SELECT Path FROM ImagesTable
WHERE ImagesTable.Id = ImageIDLookup.ImageID);
在 MySQL 上,您还可以执行如下第二步:
UPDATE ImageIDLookup
INNER JOIN ImagesTable ON ImageIDLookup.ImageID = ImagesTable.Id
SET ImageIDLookup.Path = ImagesTable.Path;
关于sqlite - 尝试从一个表到另一个表进行简单的 sql 插入但不熟悉术语?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46096226/