由于有一张比较大的表,无法上传到空间供应商的服务器(限制了最大只能上传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()'

解决方案 »

  1.   

    我建议你在数据库里面见一个view,把四张表合起来,这样不就方便多了嘛!!!
      

  2.   


    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()
      

  3.   

    "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()"
      

  4.   

    修改一下: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();
      

  5.   


    csliyu:如何建一个VIEW,能不能详细讲解一下?
      

  6.   


    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版本以上才支持。