Expand|Select|Wrap|Line Numbers
- tbl_1
- vol_key TEXT(),
- fil_id INTEGER
- type INTEGER
- tbl_2
- vol_key TEXT(),
- fil_key INTEGER
- tbl_3 (type is 1)
- vol_key TEXT(),
- fil_key INTEGER
- tbl_4 (type is 2)
- vol_key TEXT(),
- fil_key INTEGER
- tbl_5 (type is 3)
- vol_key TEXT(),
- fil_key INTEGER
Expand|Select|Wrap|Line Numbers
- SELECT tbl_1.*, tbl_2.* FROM tbl_1,tbl_2
- WHERE
- (tbl_1.vol_key='some_string'
- AND
- (tbl_2.fil_key=tbl_1.fil_id
- AND
- tbl_2.vol_key='some string'))
My question is how would I code the conditional CASEs to pull in tbl_3 - tbl_5 if they're required while not breaking the query in tbl_1 and tbl_2 if the data from the latter tables aren't needed?
Expand|Select|Wrap|Line Numbers
- SELECT tbl_1.*, tbl_2.* FROM tbl_1, tbl_2,
- CASE WHEN tbl_1.type=1 THEN tbl_3.* END AS t_3,
- CASE WHEN tbl_1.type=2 THEN tbl_4.* END AS t_4,
- CASE WHEN tbl_1.type=3 THEN tbl_5.* END AS t_5
- FROM tbl_1, tbl_2 WHERE (...)
Any ideas would be greatly appricated. TIA