我有四个数据库表,
tableA,tableB,tableC,tableD
我正在列出加入记录。这一切都很好。 我的查询如下。
Select DISTINCT A.*, B.loginname, B.email, C.full_name, C.address1, C.state, C.city, D.*
FROM (
tableA AS A
INNER JOIN tableB AS B ON B.user_id = A.id
INNER JOIN tableC AS C ON C.user_id = A.id
INNER JOIN tableD AS D ON D.user_id = A.id
) WHERE A.id = '269' ORDER BY A.created_date DESC
现在,问题是我创建了另外四个具有几乎相同细节的表,但是有不同的字段和列。所以我不能使用 UNION 。
tableE,tableF,tableG,tableH
我想合并输出到显示。输出应为ORDER BY A.created_date OR ORDER BY E.created_date
高级谢谢......
答案 0 :(得分:0)
通过声明名称别名,可以在两个具有不同命名列的表之间使用UNION ALL
(或UNION
,如果要删除重复项)。
SELECT 'first' AS source, a,b,c,d
FROM first
UNION ALL
SELECT 'second' AS source, q AS a, r AS b, s AS c, t AS d
FROM second
这将产生一个结果集(虚拟表),其中包含名为source,a,b,c,d的列。