I use UNION and LIMIT to select the earliest occurrence of a row such as a table from several tables. I need a record which table satisfied the query in the result set.
Is there a way to do something like:
SELECT id, someField, tableName FROM someUnknownTable WHERE someConditions = true
You can select tableName as a constant value:
tableName
Select id, someField, 'Table1' As tableName From table1 Union Select id, someField, 'Table2' As tableName From table2
The second alias ( As tableName ) can be omitted.
As tableName