Is there a way to query for a possible non-existent column in mysql?

Viewed 2342

I have a script where a user can select a field across multiple tables. It uses a Union to get all of the rows. Right now, I have a mapping array to indicate whether a specific field exists in each table, and if it doesn't, it uses "" as field_name to keep everything in check.

I was wondering if there is a way to reference a possibly non-existent column in a query, something like COALESCE so that if the column doesn't exist, instead of throwing an error, it just returns a default value.

1 Answers
Related