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的效率如何提高。)给点意见。!
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的效率如何提高。)给点意见。!
内连接已经是效率最高的,重点是索引如何建立的
关键是索引的优化就可以了
你可以用explain跟踪语句的执行效果来调整
如果你的address列很长的话,可以用部分前缀来建立:(sex,left(address,10))