LastLogin.find_by_sql "DELETE FROM last_logins WHERE date < (SELECT date FROM last_logins ORDER BY date DESC OFFSET 4 LIMIT 1)" \d last_logins Table "public.last_logins" Column | Type | Modifiers ---------+-----------------------------+---------------------------------------------------------- user_id | integer | date | timestamp without time zone | default now() id | integer | not null default nextval('last_logins_id_seq'::regclass) Indexes: "last_logins_pkey" PRIMARY KEY, btree (id)