我想问一下,就是有这样一个sql语句:select * from table1, table2 where table1.column1 = table2.cloumn1。
我听别人说这样的查询语句查询效率不高呀!!有没有别的语句替代,达到同样的效果。

解决方案 »

  1.   

    效率好坏不知道,执行一下试试吧。
    如果想取全项目的话,我自己试了一下,下面的这个方法最快
    select *
    from table1 t1, table t2
    where t1.column1 = t2.column1;
      

  2.   

    用子查询
    select * from table1 where table1.column1 in 
         (select table2.column1 from table2)
      

  3.   

    select * 中的 * 有点索引的意思啦*相对比较烦琐的去检索,相当于全部挨个去检索,其过程是要有匹配运算的过程的,如果是select field1,field2,field3。。from的话 就是直接去检索field1。。等字段就比方说是,你要去某地,你去问路到达目的地,和知道路线直接去。。这两种情况的区别good luck
      

  4.   

    select * from table1, table2 where table1.column1 = table2.cloumn1。
    我听别人说这样的查询语句查询效率不高呀!!有没有别的语句替代,达到同样的效果。楼主要的答案是不是这个:
    select * from table1 as t1 join table2 as t2 on(t1.column1=t2.column1)
      

  5.   

    等值连接用join...using,非等值连接用join...on
    select * from table1 as t1 join table2 as t2 on(t1.column1=t2.column1);
    select * from table1 join table2 using (column1);
      

  6.   

    先不管* 
      后面那个where还可以优化吗
    用inner也会慢吧
      

  7.   

    select * from table1 as t1 join table2 as t2 on(t1.column1=t2.column1);
    这个sql语句是不是会比较快点吧???
      

  8.   

    select * from table1, table2 where table1.column1 = table2.cloumn1
    这已经是最快的了,使用in 或 on 左连接 由连接 都没有这个快,要是在oracl里,它有个查询优化器,会优化为最优的那种。如果两个表数据大小不一样的话,表小的应该放在后面,因为执行sql时,他是从后面开始执行的。