假设我想使用 UNION 从 2 个表中获取记录。 我如何向每条记录添加一个字段来告诉我它属于哪个表?就像这样:
id | title | link | table
-----------------------------------------------------
1 | Title 1 | somelink.html | articles1
2 | Title 2 | link2 .html | articles2
3 | Title 3 | link3 .html | articles1
提前致谢?
最佳答案
select some_column, 'union_1' as from_where
from table1
union
select some_column, 'union_2' as from_where
from table2
关于MySQL : How to know which table that record belongs to in UNION result,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18607244/