質問するログイン新規登録

回答編集履歴

3

訂正

2019/12/05 01:01

投稿

sazi
sazi

スコア25430

answer CHANGED
@@ -19,4 +19,13 @@
19
19
  where exists(
20
20
  select 1 from tableB where is_reliable=1 and A_iD=A.ID
21
21
  )
22
+ ```
23
+
24
+ 上記の訂正
25
+ ```SQL
26
+ update tableA A set
27
+ answer = (select answer from tableB where A_iD=A.ID)
28
+ where ID in (
29
+ select A_iD from tableB where is_reliable=1
30
+ )
22
31
  ```

2

追記

2019/12/05 01:00

投稿

sazi
sazi

スコア25430

answer CHANGED
@@ -10,4 +10,13 @@
10
10
  > is_reliable=1の中では、A_IDに重複するものがないことがわかっています。
11
11
 
12
12
  と言われている事が前提です。
13
- 副問合せでは結果は1行以下でないとエラーになります。
13
+ 副問合せでは結果は1行以下でないとエラーになります。
14
+
15
+ is_reliable=1の件数が少ない場合は以下の方が高速かもしれません。
16
+ ```SQL
17
+ update tableA A set
18
+ answer = (select answer from tableB where A_iD=A.ID)
19
+ where exists(
20
+ select 1 from tableB where is_reliable=1 and A_iD=A.ID
21
+ )
22
+ ```

1

訂正

2019/12/03 16:12

投稿

sazi
sazi

スコア25430

answer CHANGED
@@ -1,9 +1,10 @@
1
1
  相関副問合せによって、可能です。
2
+ 実行はしていませんので悪しからず。
2
3
  ```SQL
3
4
  update tableA A set
4
- answer = (
5
+ answer = coalesce((
5
6
  select answer from tableB where is_reliable=1 and A_iD=A.ID
6
- )
7
+ ), answer)
7
8
  ```
8
9
  尚、
9
10
  > is_reliable=1の中では、A_IDに重複するものがないことがわかっています。