MySQL - Non-Existent Tables Query
Question
Currently, I have some common tables created and waiting for their respective SELECT
queries. (Including their INNER JOIN
and LEFT JOIN
instances)
I've run into occasions when a Table rarely needs to exist for some databases, but for others it will.
SELECT c.fname, c.lname, c2.colname
FROM `tbl_cus` c
LEFT JOIN `tbl_cus_optional_data` c2 ON c.cusid = c2.cusid
WHERE 1
tbl_cus_optional_data
will exist on some databases, while others will not.
When a database table does not exist MySQL
will throw an error, and the query stops, as expected.
Is there way to indicate inside the query if one of the LEFT JOIN
tables does not exist, ignore it and any columns in the SELECT portion.
I'm probably searching for a unicorn here, but I get surprised by database capabilities often enough.
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow