I've got 5 tables that are related; there are other fields in each table, but these are trouble makers.
right now, I've got the following
The above seems to work to get results from tbl_1 and tbl_2, but I also need to add the data from tbl_3 through tbl_5 when tbl_1.type is a 1, 2, or 3. I tried the CASE WHEN, but got an error near "CASE" message.
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?
I started with this, but it ended before it bagan with the error message near "CASE". I'm lost with this overly complicated exotic stuff. :D
Any ideas would be greatly appricated. TIA
Code:
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
Code:
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?
Code:
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
Comment