
Untitled
By: a guest on
Aug 8th, 2012 | syntax:
None | size: 0.74 KB | hits: 9 | expires: Never
SQLite3, Select From Two Tables One with Priority?
ID Color Value
1 red 5
2 green 3
3 yellow 5
4 blue 1
5 white 4
ID Color Value
2 green 6
3 yellow 2
5 white 3
ID Color Value
1 red 5
2 green 6
3 yellow 2
4 blue 1
5 white 3
select t1.ID, case when t2.Color is not null
then t2.Color
else t1.Color
end as Color,
case when t2.Value is not null
then t2.Value
else t1.Value
end as Value
from table1 t1
left outer join table2 t2 on t1.id = t2.id
select t1.ID,
coalesce(t2.Color, t1.Color) as Color,
coalesce(t2.Value, t1.Value) as Value
from table1 t1
left outer join table2 t2 on t1.id = t2.id