2010-11-24 83 views

回答

9

您已經在查詢該表本身。例如: - Table 1和Table

所以你基本上可以輸出表名作爲字符串本身 -

SELECT 'table1' as tableName, text from table1 
UNION 
SELECT 'table2' as tableName, text from table2 
ORDER BY date 
0

因爲你已經有了反正鍵入表名到SQL,爲什麼不把它作爲選擇中的字符串呢?即

SELECT 'table1' as tablename, text from table1 
UNION 
SELECT 'table2' as tablename, text from table2 
ORDER BY date