在 MySQL 中选择表名作为 UNION select 查询中的列
我希望能够选择行所在的表的名称作为联合选择查询中的列。像这样的事情:
SELECT [TABLENAME], text from table1
UNION
SELECT [TABLENAME], text from table2
ORDER BY date
有谁知道这是否可能? 谢谢
I want to be able to select the name of a the table a row is from as a column in a union select query. Something like this:
SELECT [TABLENAME], text from table1
UNION
SELECT [TABLENAME], text from table2
ORDER BY date
Does anyone know if this is possible?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您已经在查询该表本身。例如:- table1 和 table2
所以你基本上可以将表名称输出为字符串本身 -
You are already querying on that table itself. Eg:- table1 and table2
So you can basically output table name as string itself -
既然你必须在 sql 中输入表名,为什么不把它作为字符串包含在 select 中呢? IE
given that you've got to type the table name into the sql anyway, why not just include it as a string in the select too? i.e.