I have a table in multi language cms, and I need an UNION SELECT to select tables from all languages, Is anyway that I define the current row is from witch table? something like this:
SELECT *,lan=en FROM en_table UNION SELECT *,lan=fa FROM fa_table ...
I know that I can use this:
SELECT *,(SELECT TABLE_NAME FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA = 'db' AND TABLE_NAME = 'en_table' LIMIT 1) As lan FROM en_table UNION ...
but this is stupid idea, is better way for doing this?
Use a string literal enclosed in single quotes, with an alias as in:
Two things to note: It is unwise to use
SELECT *in aUNIONquery. Be explicit about the columns instead, so their order is deterministic.Then, if at all possible, in the long term you should combine all these tables into one, which includes a column identifying the language. That will save you from having to complicate things with
UNIONs later on.