考虑以下2个表:获取数据
Product1
----------
id
created
Product2
---------
id
created
如何我可以从Product1
和Product2
所有产品均通过created
有序?
注:Product1
和Product2
表只是举例说明我的情况,它们并不反映现实。请不要争论这件事。
考虑以下2个表:获取数据
Product1
----------
id
created
Product2
---------
id
created
如何我可以从Product1
和Product2
所有产品均通过created
有序?
注:Product1
和Product2
表只是举例说明我的情况,它们并不反映现实。请不要争论这件事。
You can Combining Result Sets by Using MySQL UNION
SELECT * FROM (select p1.id, p1.created from product1 p1
UNION ALL
select p2.id, p2.created from product2 p2) A
order by created
OR
(select p1.id, p1.created from product1 p1)
UNION ALL (select p2.id, p2.created from product2 p2)
ORDER BY created
使用交叉连接(也称为笛卡儿连接)
select product1.*, product2.* from product1 cross join product2;
只是警告说什么交叉连接它乘以记录。这里有一个答案是
mysql cross join, but without duplicated pair?
结果应该按照OP声明。 –
@ElonThan使用Order By子句修改答案。 –