B*****g 发帖数: 34098 | 1 SELECT a.id1, a.id2, d.ColumnB1, d.ColumnB2, d.ColumnC1, d.ColumnC2
FROM A a,
(SELECT b.id1, b.id2, b.ColumnB1, b.ColumnB2, NULL ColumnC1, NULL ColumnC2
FROM B b
UNION ALL
SELECT c.id1, c.id2, NULL ColumnB1, NULL ColumnB2, ColumnC1, ColumnC2
FROM C c
) d
WHERE a.id1 = d.id2
AND a.id2 = d.id2 |
|
d*h 发帖数: 2347 | 2 select A.id1, A.id2, B.ColumnB1 ColumnB1, B.ColumnB2 ColumnB2, NULL as
ColumnC1, NULL as ColumnC2
from table1 A
right join table2 B
on A.id1=B.id1
and A.id2=B.id2
union all
select A.id1, A.id2, NULL as ColumnB1, NULL as ColumnB2, C.ColumnC1 ColumnC1
, C.ColumnC2 ColumnC2
from table1 A
right join table3 C
on A.id1=C.id1
and A.id2=C.id2; |
|
d*h 发帖数: 2347 | 3 select A.id1, A.id2, B.ColumnB1 ColumnB1, B.ColumnB2 ColumnB2, NULL as
ColumnC1, NULL as ColumnC2
from A
right join B
on A.id1=B.id1
and A.id2=B.id2
union all
select A.id1, A.id2, NULL as ColumnB1, NULL as ColumnB2, C.ColumnC1 ColumnC1
, C.ColumnC2 ColumnC2
from A
right join C
on A.id1=C.id1
and A.id2=C.id2; |
|
S*********d 发帖数: 119 | 4 yah, thought about that.
Here is a tentative statement
update tableA
set columnA1 =
case
when columnA1 <> tableB.columnB1 then tableB.columnB1
end,
columnA2=
case
when columnA2 <> tableB.columnB2 then tableB.columnB2
end,
inner join tableB on
tableA.pk=tableB.pk
the problem is for the columns of tableA's that don't equal to table tableB'
s, they are still updated........with Null value, which isn't required. |
|
B*****g 发帖数: 34098 | 5 SELECT a.id1, a.id2, b.ColumnB1, b.ColumnB2, NULL ColumnC1, NULL ColumnC2
FROM A a, B b
WHERE a.id1 = b.id2
AND a.id2 = b.id2
UNION ALL
SELECT a.id1, a.id2, NULL ColumnB1, NULL ColumnB2, ColumnC1, ColumnC2
FROM A a, C c
WHERE a.id1 = c.id2
AND a.id2 = c.id2
有包子吗? |
|
n********6 发帖数: 1511 | 6 我的土办法,不知是否可行。
1。把id1, id2连起来,变成id3。
2。
SELECT A.ID3, B.ColumnB1, B.ColumnB2, C.ColumnC1, C.ColumnC2
FROM A LEFT JOIN B ON A.ID3 = B.ID3
RIGHT JOIN C ON A.ID3 = B.ID3
细节和优化方案正在思索中。 |
|