我試圖更新數據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