有两种不同的表格,我希望它们合二为一:
表1:
+-------------+------------+
| ProdCode | QTY |
+-------------+------------+
| 1 | 1 |
+-------------+------------+
| 2 | 4 |
+-------------+------------+
| 3 | 4 |
+-------------+------------+
| 4 | 5 |
+-------------+------------+
表2:
+-------------+------------+
| MatCode | QTY |
+-------------+------------+
| ZZ | 21 |
+-------------+------------+
| AA | 44 |
+-------------+------------+
| RR | 44 |
+-------------+------------+
| QQ | 52 |
+-------------+------------+
最终结果:
+-------------+------------+
| Code | QTY |
+-------------+------------+
| 1 | 1 |
+-------------+------------+
| 2 | 4 |
+-------------+------------+
| 3 | 4 |
+-------------+------------+
| 4 | 5 |
+-------------+------------+
| ZZ | 21 |
+-------------+------------+
| AA | 44 |
+-------------+------------+
| RR | 44 |
+-------------+------------+
| QQ | 52 |
+-------------+------------+
如果ProdCode和MatCode不相关,是否可以这样做?
答案 0 :(得分:4)
SELECT ProdCode, QTY FROM [table1]
UNION ALL
SELECT MatCode, QTY FROM [table2]
这将从两个表中选择记录并将它们作为一个结果集返回。