回答編集履歴
6
変更
answer
CHANGED
File without changes
|
5
変更
answer
CHANGED
@@ -18,9 +18,9 @@
|
|
18
18
|
-- |4|c|
|
19
19
|
-- |6|d|
|
20
20
|
|
21
|
-
update テーブルA set P=
|
21
|
+
update テーブルA set P=テーブルB.P
|
22
|
-
from
|
22
|
+
from テーブルB
|
23
|
-
where テーブルA.id=
|
23
|
+
where テーブルA.id=テーブルB.id;
|
24
24
|
|
25
25
|
または
|
26
26
|
|
4
変更
answer
CHANGED
@@ -22,6 +22,12 @@
|
|
22
22
|
from (select * from テーブルB) t1
|
23
23
|
where テーブルA.id=t1.id;
|
24
24
|
|
25
|
+
または
|
26
|
+
|
27
|
+
update テーブルA set P=t1.P
|
28
|
+
from (select テーブルB.id, テーブルB.P from テーブルB join テーブルA using(id)) t1
|
29
|
+
where テーブルA.id=t1.id;
|
30
|
+
|
25
31
|
id | 列2 | p
|
26
32
|
----+-----+---
|
27
33
|
1 | あ | a
|
3
変更
answer
CHANGED
@@ -22,4 +22,11 @@
|
|
22
22
|
from (select * from テーブルB) t1
|
23
23
|
where テーブルA.id=t1.id;
|
24
24
|
|
25
|
+
id | 列2 | p
|
26
|
+
----+-----+---
|
27
|
+
1 | あ | a
|
28
|
+
2 | い | b
|
29
|
+
3 | う |
|
30
|
+
6 | か | d
|
31
|
+
(4 rows)
|
25
32
|
```
|
2
変更
answer
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
|
1
|
+
テーブルAに有るものだけテーブルBで更新を行っています。
|
2
2
|
```sql
|
3
|
-
create temp table テーブルA (id int, 列2 text);
|
3
|
+
create temp table テーブルA (id int, 列2 text, P text);
|
4
|
-
insert into テーブルA values
|
4
|
+
insert into テーブルA (id, 列2) values
|
5
5
|
(1,'あ'),(2,'い'),(3,'う'),(6,'か');
|
6
6
|
-- |id|列2|
|
7
7
|
-- |1|あ|
|
@@ -18,16 +18,8 @@
|
|
18
18
|
-- |4|c|
|
19
19
|
-- |6|d|
|
20
20
|
|
21
|
+
update テーブルA set P=t1.P
|
21
|
-
select
|
22
|
+
from (select * from テーブルB) t1
|
22
|
-
left join テーブルB t2 using(id)
|
23
|
-
|
23
|
+
where テーブルA.id=t1.id;
|
24
|
-
;
|
25
24
|
|
26
|
-
id | 列2 | p
|
27
|
-
----+-----+---
|
28
|
-
1 | あ | a
|
29
|
-
2 | い | b
|
30
|
-
3 | う |
|
31
|
-
6 | か | d
|
32
|
-
(4 rows)
|
33
25
|
```
|
1
変更
answer
CHANGED
@@ -22,4 +22,12 @@
|
|
22
22
|
left join テーブルB t2 using(id)
|
23
23
|
order by t1.id
|
24
24
|
;
|
25
|
+
|
26
|
+
id | 列2 | p
|
27
|
+
----+-----+---
|
28
|
+
1 | あ | a
|
29
|
+
2 | い | b
|
30
|
+
3 | う |
|
31
|
+
6 | か | d
|
32
|
+
(4 rows)
|
25
33
|
```
|