我试图更新数据1的ID到RECORD2的ID时:SQLite的 - 更新基于值从其他两个表列列
- 记录1的和Record2的名称是一样的,和
- 重量大于记录2。
记录1
| ID | Weight | Name |
|----|--------|------|
| 1 | 10 | a |
| 2 | 10 | b |
| 3 | 10 | c |
RECORD2
| ID | Weight | Name |
|----|--------|------|
| 4 | 20 | a |
| 5 | 20 | b |
| 6 | 20 | c |
数据1
| ID | Weight |
|----|--------|
| 4 | 40 |
| 5 | 40 |
我曾尝试以下SQLite的查询:
update data1
set id =
(select record2.id
from record2,record1
where record1.name=record2.name
and record1.weight<record2.weight)
where id in
(select record1.id
from record1, record2
where record1.name=record2.name
and record1.weight<record2.weight)
使用上面的查询数据1的ID更新为4的所有记录。
注:记录1的ID是数据1外键。
@CL。这个问题使用三个表格,我无法使用您为此提供的相同查询。 – Prabha
如果我编写查询的建议然后它不识别record1.name 更新DATA1 设定ID = (从RECORD2 其中record1.name = record2.name 和record1.weight
Prabha