UNION を使うと重複除去されるので
UNION ALLを使って、全件抽出したあと、
優先順位を指定する。
table:ta1
---------------
id,col1
---------------
1,a
2,b
---------------
table:ta2
---------------
id,col1
---------------
2,c
3,d
---------------
ta1を優先として、レコードのid2は、ta1のほうを抽出する
SQL
select id, priority, col1, seq from( select id, priority, col1, ROW_NUMBER() OVER(PARTITION BY id ORDER BY priority) AS seq from( select id, col1, 1 as priority from ta1 union all select id, col1, 2 as priority from ta2 )ta3 ) ta4 where ta4.seq = 1
— posted by midilin @ 03:12PM
| Comment (0)
最近のコメント