以前做东西遇到了union all的问题,因为这个只有mysql的高版本才有,所以很少用到,
在orderby的时候总是出现问题原来的语句是这样的
不管怎么搞里面的order by都不起作用,最后查了相关问题,才知道问题的所在
正确的代码应该如下:
select * from(
SELECT *
FROM news
WHERE screatedate > '2007-06-30'
order BY typeid
) as temp1
UNION ALL select * from(
SELECT *
FROM news
WHERE screatedate <= '2007-06-30'
order BY screatedate desc
)as temp2
最后终于成功了,现在贴出来,供大家参考
在orderby的时候总是出现问题原来的语句是这样的
select * from(
SELECT *
FROM news
WHERE screatedate > '2007-06-30'
order BY typeid
)
UNION ALL select * from(
SELECT *
FROM news
WHERE screatedate <= '2007-06-30'
order BY screatedate desc
)
SELECT *
FROM news
WHERE screatedate > '2007-06-30'
order BY typeid
)
UNION ALL select * from(
SELECT *
FROM news
WHERE screatedate <= '2007-06-30'
order BY screatedate desc
)
不管怎么搞里面的order by都不起作用,最后查了相关问题,才知道问题的所在
正确的代码应该如下:
select * from(
SELECT *
FROM news
WHERE screatedate > '2007-06-30'
order BY typeid
) as temp1
UNION ALL select * from(
SELECT *
FROM news
WHERE screatedate <= '2007-06-30'
order BY screatedate desc
)as temp2
最后终于成功了,现在贴出来,供大家参考
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/1566/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
最后编辑: jackxiang 编辑于2009-11-1 12:35
评论列表
2009-10-29 17:47 | 扬漾
,,真是帮了忙啊,,,
分页: 1/1 1