select top 10 title,writer from tt order by 发布时间 试试
试试这个,我将发布时间以倒序排列的: select temp.title, temp.writer, temp.发布时间 from ( select title, writer, 发布时间 from table1 where rownum=10 order by 发布时间 desc union select title, writer, 发布时间 from table2 where rownum=10 order by 发布时间 desc union select title, writer, 发布时间 from table3 where rownum=10 order by 发布时间 desc union select title, writer, 发布时间 from table4 where rownum=10 order by 发布时间 desc ) temp where rownum=10 order by 发布时间 desc
不好意思,这个是oracle的,你将 select title, writer, 发布时间 from table3 where rownum=10 order by 发布时间 desc 改为 select title, writer, 发布时间 from table3 order by 发布时间 desc limit 10 其他的rownum都改正这样
是这样么 select temp.title, temp.writer, temp.pubdate from ( select title, writer, pubdate from table1 order by pubdate desc limit 10 union select title, writer, pubdate from table2 rder by pubdate desc limit 10 union select title, writer, pubdate from table3 rder by pubdate desc limit 10 union select title, writer, pubdate from table4 rder by pubdate desc limit 10 )temp where rownum=10 order by pubdate desc 但是还是不行
最后的那个where rownum=10 也要修改的
select temp.title, temp.writer, temp.pubdate from ( select title, writer, pubdate from table1 order by pubdate desc limit 10 union select title, writer, pubdate from table2 rder by pubdate desc limit 10 union select title, writer, pubdate from table3 rder by pubdate desc limit 10 union select title, writer, pubdate from table4 rder by pubdate desc limit 10 )temp order by temp.pubdate desc limit 10
select temp.title, temp.writer, temp.pubdate from ( select title, writer, pubdate from table1 order by pubdate desc limit 10 union select title, writer, pubdate from table2 order by pubdate desc limit 10 union select title, writer, pubdate from table3 order by pubdate desc limit 10 union select title, writer, pubdate from table4 order by pubdate desc limit 10 )temp order by pubdate desc limit 10 我最终是这样,但是还是不行
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'select title, writer, pubdate from dede_archives17 order by pub - Execute Query False! select temp.title, temp.writer, temp.pubdate from ( select title, writer, pubdate from dede_archives17 order by pubdate desc limit 10 union select title, writer, pubdate from dede_archives18 order by pubdate desc limit 10 union select title, writer, pubdate from dede_archives19 order by pubdate desc limit 10 union select title, writer, pubdate from dede_archives20 order by pubdate desc limit 10 )temp order by temp.pubdate desc limit 10
我看不出有什么问题了,要不你试试加上别名: select temp.title, temp.writer, temp.pubdate from ( select a.title, a.writer, a.pubdate from dede_archives17 as a order by a.pubdate desc limit 10 union select b.title, b.writer, b.pubdate from dede_archives18 as b order by b.pubdate desc limit 10 union select c.title, c.writer, c.pubdate from dede_archives19 as c order by c.pubdate desc limit 10 union select d.title, d.writer, d.pubdate from dede_archives20 as d order by d.pubdate desc limit 10 ) temp order by temp.pubdate desc limit 10 还有你查一下你的mysql版本是多少。
select * from ( select * from table1 union select * from table2 union select * from table3 union select * from table4 )temp order by pubdate desc limit 10
试试这个看看: (select title, writer, pubdate from dede_archives17 order by pubdate desc limit 10) UNION (select title, writer, pubdate from dede_archives18 order by pubdate desc limit 10) UNION (select title, writer, pubdate from dede_archives19 order by pubdate desc limit 10) UNION (select title, writer, pubdate from dede_archives20 order by pubdate desc limit 10) ORDER BY pubdate desc limit 10;
从这个结果中 查title writer 按日期排序 取前十个 就出来了
试试
select temp.title, temp.writer, temp.发布时间
from
(
select title, writer, 发布时间 from table1 where rownum=10 order by 发布时间 desc
union
select title, writer, 发布时间 from table2 where rownum=10 order by 发布时间 desc
union
select title, writer, 发布时间 from table3 where rownum=10 order by 发布时间 desc
union
select title, writer, 发布时间 from table4 where rownum=10 order by 发布时间 desc
) temp
where rownum=10
order by 发布时间 desc
select title, writer, 发布时间 from table3 where rownum=10 order by 发布时间 desc
改为
select title, writer, 发布时间 from table3 order by 发布时间 desc limit 10
其他的rownum都改正这样
select temp.title, temp.writer, temp.pubdate
from
(
select title, writer, pubdate from table1 order by pubdate desc limit 10
union
select title, writer, pubdate from table2 rder by pubdate desc limit 10
union
select title, writer, pubdate from table3 rder by pubdate desc limit 10
union
select title, writer, pubdate from table4 rder by pubdate desc limit 10
)temp
where rownum=10
order by pubdate desc
但是还是不行
from
(
select title, writer, pubdate from table1 order by pubdate desc limit 10
union
select title, writer, pubdate from table2 rder by pubdate desc limit 10
union
select title, writer, pubdate from table3 rder by pubdate desc limit 10
union
select title, writer, pubdate from table4 rder by pubdate desc limit 10
)temp
order by temp.pubdate desc limit 10
from
(
select title, writer, pubdate from table1 order by pubdate desc limit 10
union
select title, writer, pubdate from table2 order by pubdate desc limit 10
union
select title, writer, pubdate from table3 order by pubdate desc limit 10
union
select title, writer, pubdate from table4 order by pubdate desc limit 10
)temp
order by pubdate desc limit 10
我最终是这样,但是还是不行
select temp.title, temp.writer, temp.pubdate from
(
select a.title, a.writer, a.pubdate from dede_archives17 as a order by a.pubdate desc limit 10
union
select b.title, b.writer, b.pubdate from dede_archives18 as b order by b.pubdate desc limit 10
union
select c.title, c.writer, c.pubdate from dede_archives19 as c order by c.pubdate desc limit 10
union
select d.title, d.writer, d.pubdate from dede_archives20 as d order by d.pubdate desc limit 10
) temp
order by temp.pubdate desc limit 10
还有你查一下你的mysql版本是多少。
from
(
select * from table1
union
select * from table2
union
select * from table3
union
select * from table4
)temp order by pubdate desc limit 10
(select title, writer, pubdate from dede_archives17 order by pubdate desc limit 10)
UNION
(select title, writer, pubdate from dede_archives18 order by pubdate desc limit 10)
UNION
(select title, writer, pubdate from dede_archives19 order by pubdate desc limit 10)
UNION
(select title, writer, pubdate from dede_archives20 order by pubdate desc limit 10)
ORDER BY pubdate desc limit 10;