我希望使用find在rails控制器中编写这个SQL查询:
select id,name from questions where id not in (select question_id from levels_questions where level_id=15)
我该怎么做?我正在使用Rails框架和MysqL.
提前致谢.
解决方法
简单方法:
ids = LevelsQuestion.all(:select => "question_id",:conditions => "level_id = 15").collect(&:question_id) Question.all(:select => "id,name",:conditions => ["id not in (?)",ids])
一枪:
Question.all(:select => "id,:conditions => ["id not in (select question_id from levels_questions where level_id=15)"])