楼上的sql意思是说取出table1 table2 table3 内10条数据嘛?
select * from table1  by hit desc limit 10 
union 
select * from table2  by hit desc limit 10 
union 
select * from table3 by hit desc limit 10就可以了 不用再在外面加select* from ()了吧没研究过union和join的快慢 个人感觉join快吧。

解决方案 »

  1.   

    数据查询的连接都不快,建议你用这一种: 分别查处每个表最快的10个,然后用PHP排序
     
       
      

  2.   

    1.你这两个SQL根本就是在表达两个意义
    2.最好用join
    3.SQL的速度跟索引有很大关系
      

  3.   

    left join和right join.
    并且限制取出的条数.
      

  4.   

    explain +语句
    比较一下
      

  5.   

    你要的答案是“第二种快”,原因是中间结果集小
    可以不用子查询的(select * from table1 order by hit desc limit 10)
    union
    (select * from table2 order by hit desc limit 10)
    union
    (select * from table2 order by hit desc limit 10)
    order by hit desc limit 10;这句就可以完成。另外,对于相同结构,同类数据的多个表一起查询时,可以使用merge表
    create table table_merge ( id int(10) unsigned not null auto_increment, title varchar(255) not null default '', hit int(10) unsigned not null, primary key (id),key hit(hit)) ENGINE=merge UNION=(table1,table2,table3) INSERT_METHOD=FIRST;
    然后select * from table_merge order by hit desc limit 10;