I have a situation here. Currently I have
- two polling tables (poll_one and poll_two) which will poll data from outside data-source. This two tables will keep interchange between each other.
- one checking table (check_poll) which tells me which tables (poll_one or poll_two) is active
- one user edit table (edit) which stores exact same columns and names as the two poll tables.
Basically I wan to create a dbview that joins the edit table and the active poll table. However, I am not sure how to do a conditional dbview to first check which polling table is active before performing my query.
I cannot use stored procedures as this dbview will be used for my hibernate mapping.
Below is a sample definition of my dbview:
SELECT CASE WHEN u.name IS NULL THEN p.name ELSE u.name END AS name, CASE WHEN u.size IS NULL THEN p.size ELSE u.size END AS size, //same for the rest of columns FROM user_edit_table u LEFT JOIN poll_one p //I wan to make this conditional ON p.id = u.id
Is it possible? Is there any other ways?
So based on the check table, I will choose which table I wan to left join. There is no foreign relation between the tables. All are stand alone.