Copy records between tables with sql

To copy records between tables with sql:
sql = "INSERT INTO batch_items (batch_id, mailuser_id, sendstate_id )
SELECT DISTINCT #{@batch_id}, mailuser_id, 2
FROM
subscriptions s, mailusers m
WHERE
template_id = #{@newsletter.template_id}
AND s.active = 1
AND m.client_id = #{@newsletter.client_id}
AND s.mailuser_id =m.id"

conn = ActiveRecord::Base.connection()
conn.execute sql

Comments are closed.