table 1id,
name,
no,
sex,
age,
address
other
------------------
table2id_
name,
no,
sex,
age.
address
要求如果 table1.sex=table2.sex ,table1.address=table2.address一样的话,查询出table1的other
列,和table2的所有列
select a.other,b. id_,b.name,b.no,b.sex from  table1 a ,table2 b where a.sex=b.sex and a.address=b.address
------------
我的需求就是这样,大家看看 我这样写SQL的效率如何提高。)给点意见。!

解决方案 »

  1.   

    索引情况、EXPLAIN SQL语句,贴结果
    内连接已经是效率最高的,重点是索引如何建立的
      

  2.   

    你这个语句是直接内联接,已经是很好的咯
    关键是索引的优化就可以了
    你可以用explain跟踪语句的执行效果来调整
      

  3.   

    建立复合索引 (sex,address)看看
    如果你的address列很长的话,可以用部分前缀来建立:(sex,left(address,10))
      

  4.   

    创建索引create index idx_table2 on table2(sex,address);