楼上的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快吧。
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快吧。
解决方案 »
- php的广告联盟程序外包,公司地点在深圳
- php判断用户输入验证码是否正确
- 无法理解正则表达式中的“前向和后向断言”
- 关于apache的问题
- PHP MySQL问题 left join 连select * from table_nem 都错误了 怎么办?
- 简单问题,散分了
- 我的数据库字符格式为UTF-8,取出数据后中文为乱码。怎样解决啊?谢谢!
- 用php编程实现将txt,doc等文件转化成pdf格式.
- 大家看一看!想一想!猜一猜!它為什麼要出錯??<A HREF=javascript:history.go(-1);>RETURNS</A>
- 请教正则匹配,有个小疑惑
- 做为中间服务器,在两台服务器间接收发送数据(急急急!!!)
- 这个变量为什么不能用?
2.最好用join
3.SQL的速度跟索引有很大关系
并且限制取出的条数.
比较一下
可以不用子查询的(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;