如何将两个表合并为一个带有表源的新字段?

时间:2015-05-21 18:42:42

标签: mysql sql database select

table one
+-----+--------+--------+
|date |index   |idOne   |
|-----+--------|--------+
|     |        |        |

table two
+-----+--------+--------+
|date | index  | idTwo  |
|-----+--------|--------+
|     |        |        |


query result where index = "5"

+---------+--------+--------+----------+
|date     | index  |   id   |  idType  |
|---------+--------|--------+----------+
|10/10/91 |   5    |   1    |   One    |
|10/11/91 |   5    |   2    |   One    |
|10/12/91 |   5    |   1    |   Two    |

这些是相关问题但不一样

这个没有不同的领域 I want to combine/union two tables and have it create a field that identifies which table it came from

这个没有表区别字段
Combine two tables that have no common fields

1 个答案:

答案 0 :(得分:4)

您可以使用http://www.test.com/ENTERSOMETHINGHERE/html/stuff/ 运算符加入这两个查询,并通过选择文字添加union all列:

idType