[英]MySQL - Display data from TWO tables in ONE Column in TWO rows
My Problem is the following: 我的问题如下:
I have two tables with the same datatypes. 我有两个具有相同数据类型的表。 One is called "rechnung" and one "rechnungarchiv".
一种叫做“ rechnung”,另一种叫做“ rechnungarchiv”。
Example row: 示例行:
Rg_ID | Rg_KdID | Rg_Datum | Rg_Summe | Rg_AnzPos
DB5 |4711 |2010-etc. |2500.00 | 5
One table holds up-to-date data, the other one is an archive for old data. 一个表保存最新数据,另一个表保存旧数据。 Now I have to display eg Rg_ID and RgAr_ID (two ID with the same format) in one column, but in two rows.
现在,我必须在一列但两行中显示例如Rg_ID和RgAr_ID(具有相同格式的两个ID)。 This is my Query so far:
到目前为止,这是我的查询:
SELECT
CONCAT(r.Rg_ID, a.RgAr_RgID) AS RechnungsID,
CONCAT(r.Rg_KdID, a.RgAr_KdID) AS KundenID,
CONCAT(r.Rg_Datum, a.RgAr_Datum) AS RechnungsDatum,
CONCAT(r.Rg_Summe, a.RgAr_Summe) AS RechnungsSumme
FROM rechnung AS r
INNER JOIN rechnungarchiv AS a
ON r.Rg_KdID = a.RgAr_KdID
What I get is this: 我得到的是:
DB5DB1 47114711 2010-06-03 00:00:002009-10-11 00:00:00 2500.00003725.0000
I simply want only data from one table at a time to be displayed. 我只希望一次只显示一个表中的数据。 How do I do this?
我该怎么做呢?
Thanks in advance. 提前致谢。
You're looking for the UNION operation: 您正在寻找UNION操作:
SELECT 'rechnung' AS type, rechnung.*
FROM rechnung
UNION
SELECT 'archiv' AS type, rechnungarchiv.*
FROM rechnungarchiv;
See this fiddle: http://sqlfiddle.com/#!9/04e31e/12 看到这个小提琴: http ://sqlfiddle.com/#!9/ 04e31e/12
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.