It sounds like want you want to do is:
- Outer join the price tables to article
- Use coalesce to find return the first non-null
create table t1 (
x int, y int
);
create table t2 (
x int, y int
);
create table t3 (
x int, y int
);
insert into t1 values (1, 1);
insert into t1 values (2, 1);
insert into t1 values (3, 1);
insert into t2 values (1, 2);
insert into t2 values (2, 2);
insert into t3 values (1, 3);
select t1.x, coalesce(t3.y, t2.y, t1.y)
from t1
left join t2
on t1.x = t2.x
left join t3
on t1.x = t3.x;
X COALESCE(T3.Y,T2.Y,T1.Y)
1 3
2 2
3 1
If this doesn't help, please give specific examples of what you're trying to do. These should include:
- Create tables
- Insert into tables
- Expected output from your queries