我现在有a,b,c三个表,a:id,nick,iidb:id,nick,cityc:id,iid,cid
我现在需要检索出a.*,b.city,c.cid条件
a.nick=b.nick,a.iid=c.iid,c.cid='num'(num=某值);
怎么样做才能够最有效率用直接select还是用inner join 或者其他表中数据很大.

解决方案 »

  1.   

    select a.*,b.city,c.cid from a 
    inner join b on a.nick=b.nick
    inner join c on a.iid=c.iid and c.cid='num'
      

  2.   

    我测试过  用
    select a.*,b.city,c.cid from a,b,c where a.nick=b.nick and c.cid="num" and a.iid=c.iid要比inner join 要来的稍微快一点...数据量少的情况下join要快我现在a表有1000条,b有120条,c有1000条直接select要快一点点
      

  3.   

    在连接字段上建立索引没有?直接select要快一点点
    SQL语句是什么?
      

  4.   

    如果在相同的情况下,一般而言,INNER JOIN速度最快,EXPLAIN你的SQL语句,贴结果
      

  5.   

    show index from a;
    show index from b;
    show index from c;explain select a.*,b.city,c.cid from a,b,c where a.nick=b.nick and c.cid="num" and a.iid=c.iid;看一下你的分析结果是什么。select a.*,b.city,c.cid 
    from a  inner join b on a.nick=b.nick
      inner join c on a.iid=c.iid 
    where c.cid='num'这句和你的应该一样。一般不要把 where 句话到 连接条件中,这样会影响MYSQL的优化。
      

  6.   

    1 SIMPLE b ALL 24 Using temporary
    1 SIMPLE c ALL 80 Using where
    1 SIMPLE a ALL 75 Using whereexplain select distinct  a.*, b.seller_credit_score as credit,
                  b.location_city as city
                  from tbk_item a,user b,item c where
                  a.nick = b.nick and c.cid='$_cid' and c.iid=a.iid结果
      

  7.   

    show index from a;
    show index from b;
    show index from c;也贴出来看下。另外把两种方式的SELECT都 explain 一下。