views:

64

answers:

1

I'm trying to delete few records from table 'abc' where id is fetched from 'xyz' table

SQL:

delete from abc where id in (select ids from xyz where i= 10)

this query i want to execute using find_by_sql to avoid multiple hits to database.

It's giving error. Please help me in getting this delete action done in a single hit to DB.

+1  A: 

I don't think find_by_sql is the method you want.

If you have

class Abc < ActiveRecord::Base
end

(so abc.rb is your model) then I think you should be able to do something like this:

Abc.connection.execute('delete from abc where id in (select ids from xyz where i= 10)')
Mike Woodhouse
it worked. thanks so much