For this example I have eliminated (most of) the unreferenced
columns from the table definitions.
My problem is: how does one formulate a select statement or
create a view in SQL (I'm using MySQL (Ver 14.7 Distrib 4.1.16))
that implements the pseudo-code that follows the table
definitions? BTW, I _have_ read the manual (several times).
create table t2 ( # about 1K rows
n2 smallint unsigned not null auto_increment unique key,
n1 smallint unsigned not null references t1 (n1),
s2 varchar(90) primary key);
create table t3 ( # about 50K rows
n3 mediumint unsigned not null auto_increment unique key,
s3 varchar(99) primary key);
create table t4 ( # about 1.6M rows
k4 char(15) primary key,
dn mediumint unsigned references t3 (n3),
vn smallint unsigned references t2 (n2),
s4 varchar(120) not null);
create table t5 ( # about 30K rows
k5 char(15) not null key references t4 (ik),
vn smallint unsigned not null references t2 (n2));
If I were doing this in a procedural language, I would:
loop for each row of t5
using row from t4 with t4.k4==t5.k5
// row always exists and t4.vn != t5.vn when t4.k4==t5.k5
if dn NULL go to top of loop end_if // 60%-80% are NULL
display t1.s1 as ac where t1.n1==t5.vn
display t1.s1 as ai where t1.n1==t4.vn
display t4.s4 as fn
display t3.s3 as di where t3.n3==t4.dn
end_using
end_loop
TIA