views:

91

answers:

1

I have a DB which has a table called config. This table could possibly have a config_cstm table that is related by the id to the config table.

I was wondering - is there a way to dynamically check for the existence of this table in one simple select statement?

In other words, something like:

select * 
from   config 
(IF EXISTS config_cstm THEN 
           LEFT OUTER JOIN config_cstm ON config.id = config_cstm.id_c)

I know how I would go about checking for the existence of an existing table in PHP. I was wanting to do this all in one MySQL statement though.

Any suggestions?

A: 

If you're using MySQL 5 or better, you can use CASE for that sort of conditional functionality.

IMHO, however, if you're using php, you should do it in php rather than trying to shoehorn it all into a SQL query. It's usually not very efficient.

Satanicpuppy