我有两个没有共同点的独立表格,因此我无法对它们进行任何加入。
我想要的是以这种方式将结果相交,以便按日期对整体结果(table1 + table2)进行排序。
EG:
table1, row1
table1, row5
table2, row1
table1, row3
table2, row7
答案 0 :(得分:1)
您可以通过union all
形成子查询然后对结果进行排序来完成此操作。
SELECT * FROM (
SELECT field1 AS a, field2 AS b, field3 AS c, fieldn AS date_for_order
FROM table1
UNION
SELECT fieldx AS a, fieldy AS b, fieldz AS c, fieldw AS date_for_order
FROM table2
) joined_tables
ORDER BY date_for_order
重要的是为两个表中的字段创建相同的别名,这是对UNION的要求。
结果将是:
a | b | c | date_for_order