如何从多张同类型表中查询数据

jupiter418 2009-10-05 10:39:15
由于有一张比较大的表,无法上传到空间供应商的服务器(限制了最大只能上传4M的文件),因此只好将这张表分割成4张表。请教如何从这4张同类型表中查询数据,就象查询1张表一样。

一张表时查询语句如下:
select * from wuyan where z1="'.$f.'"'.'order by rand()'
改成四张表后,查询语句如下,但执行时出错,请教如下修改:
select * from wuyan_a,wuyan_b,wuyan_c,wuyan_d where z1="'.$f.'"'.'order by rand()'
...全文
91 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
阿_布 2009-10-06
  • 打赏
  • 举报
回复

create view view_wuyan as
select * from wuyan_a where z1='".$f."'
union all
select * from wuyan_b where z1='".$f."'
union all
select * from wuyan_c where z1='".$f."'
union all
select * from wuyan_c where z1='".$f."';

select * from view_wuyan order by rand();

mysql视图要在mysql5.1版本以上才支持。
jupiter418 2009-10-06
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 csliyu 的回复:]
我建议你在数据库里面见一个view,把四张表合起来,这样不就方便多了嘛!!!
[/Quote]

csliyu:如何建一个VIEW,能不能详细讲解一下?
阿_布 2009-10-06
  • 打赏
  • 举报
回复
修改一下:

select * from wuyan_a where z1='".$f."'
union all
select * from wuyan_b where z1='".$f."'
union all
select * from wuyan_c where z1='".$f."'
union all
select * from wuyan_d where z1='".$f."'
order by rand();
  • 打赏
  • 举报
回复
"select * from wuyan_a as a,wuyan_b as b,wuyan_c as,wuyang_d as d where a.z1 = b.z1 and b.z1 = c.z1 and c.z1 = d.z1 and d.z1 = '$f' order by rand()"
阿_布 2009-10-06
  • 打赏
  • 举报
回复

select * from wuyan_a where z1='".$f."' order by rand()
union all
select * from wuyan_b where z1='".$f."' order by rand()
union all
select * from wuyan_c where z1='".$f."' order by rand()
union all
select * from wuyan_d where z1='".$f."' order by rand()
csliyu 2009-10-06
  • 打赏
  • 举报
回复
我建议你在数据库里面见一个view,把四张表合起来,这样不就方便多了嘛!!!

21,890

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧