SELECT time,
null as postid,
designid,
custid
FROM approveddesign
WHERE designerid='abc@gmail.com'
UNION
SELECT time,
postid,
null as designid,
null as custid
FROM applycontest
WHERE approval='approved' and designerid='abc@gmail.com'
ORDER BY 'time' ASC
按时间排序不起作用,因为时间列仅包含数值。
答案 0 :(得分:1)
删除ORDER BY
子句中col名称周围的引号。
[...] ORDER BY time ASC
答案 1 :(得分:1)
将'time'
更改为time
为ORDER BY time ASC
答案 2 :(得分:0)
可以将排序列指定为名称或列别名,或者表示选择列表中名称或别名位置的非负整数。
如果您真的想订购所有结果,请使用:
SELECT *
FROM (
SELECT time,
null as postid,
designid,
custid
FROM approveddesign
WHERE designerid='abc@gmail.com'
UNION ALL
SELECT time,
postid,
null as designid,
null as custid
FROM applycontest
WHERE approval='approved' AND designerid='abc@gmail.com'
) t
ORDER BY 1
我还将UNION
更改为UNION ALL
以获得更好的效果,但不会删除重复的行,如果您想删除这些重复的行,我建议您添加DISTINCT
在SELECT
之后:
SELECT DISTINCT *
FROM (
...
) t
ORDER BY time