两张表: 
questions:question_id , question (主键:question_id) 
answers:answer_id , question_id , answer(主键:answer_id,外键:question_id对应表questions的 question_id) question和answer是一对多的关系,一个问题有多个答案。 
我现在想选择question和answer两个字段,并且question和answer都有一定的条件,最基本的语句是: 
select question,answer 
from questions,answers 
where questions.question_id = answers.question_id 
      and question... 
      and answer... 但是questions和answers两张表数据量很多,有几十万条,这样的情况下用上面的sql语句的话,效率 相当低,怎么样写sql语句效率比较高? 谢谢各位。

解决方案 »

  1.   

    大家说要加索引。
    questions里的question_id以及answers里的answer_id都是主键,他们好像都自动被建为索引。oracle里是这样的吗?
      

  2.   

    come on
    sql server这边人气就是足
    还有question和answer的条件写在哪里?用where?
      

  3.   


    上面你写的是对的,ANSWER_ID 建立索引。。这种查询已经是很高效的方式了。。
      

  4.   

    可是answer_id是主键,主键已经是索引了吧?oracle里是这样的吧?
      

  5.   

    这边inner join基本上对效率贡献有限,加索引是必须的。
      

  6.   

    再次请教大家,answer_id是主键,主键自动是索引了吧?oracle里是这样的吗?
    再次请教大家,answer_id是主键,主键自动是索引了吧?oracle里是这样的吗?
    再次请教大家,answer_id是主键,主键自动是索引了吧?oracle里是这样的吗?
    再次请教大家,answer_id是主键,主键自动是索引了吧?oracle里是这样的吗?
    再次请教大家,answer_id是主键,主键自动是索引了吧?oracle里是这样的吗?