这是我上次尝试过的。
(
SELECT
`offers`.`id` AS `offer`, `offers`.`date`
from `offers`
WHERE `offers`.`expired`='0'
ORDER BY `offers`.`date` DESC LIMIT 10
)
UNION ALL
(
SELECT
`vlog`.`video`,
`vlog`.`updated`
from `vlog`
ORDER BY `vlog`.`date` DESC LIMIT 10
)
为简单起见,我只有两列。我需要按日期排序(不是上面代码提供的相同结果),并显示哪个是优惠,哪个是视频。这是否可能没有链接表的列。?
答案 0 :(得分:1)
我假设video.video
是一个ID,因为它与顶部查询中的id
列对齐。您可以在两个查询中选择一个文字字符串,以指示它来自哪个查询:
SELECT
'offer' AS type,
id,
date
FROM
offers
WHERE
expired = 0
UNION
SELECT
'video' AS type,
video AS id,
updated AS date
FROM
vlog
ORDER BY
date