table1,table2,table3,table4
4个表都是相同表,字段也相同
我现在想查询4个表中的title,和writer这2个字段(要相对应)的10条记录,按发布时间排列
请问如何写

解决方案 »

  1.   

    四个表union 一下
    从这个结果中 查title writer 按日期排序 取前十个 就出来了
      

  2.   

    select top 10 title,writer from tt order by 发布时间
    试试
      

  3.   

    试试这个,我将发布时间以倒序排列的:
    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
      

  4.   

    不好意思,这个是oracle的,你将
    select title, writer, 发布时间 from table3 where rownum=10 order by 发布时间 desc 
    改为
    select title, writer, 发布时间 from table3 order by 发布时间 desc limit 10
    其他的rownum都改正这样
      

  5.   

    是这样么
    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
    但是还是不行
      

  6.   

    最后的那个where rownum=10 也要修改的 
      

  7.   

    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
     
      

  8.   

    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 
    我最终是这样,但是还是不行
      

  9.   

    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
      

  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版本是多少。
      

  11.   

    select *
    from   

    select * from table1 
    union  
    select * from table2  
    union  
    select * from table3 
    union  
    select * from table4 
    )temp  order by pubdate desc limit 10  
      

  12.   

    试试这个看看:
    (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;