Remove duplicate rows based on one column sql
(Tuesday, February 22, 2011, at 01:03 AM)
http://www.codeunit.co.za/2010/06/25/sql-finding-duplicate-rows-based-on-multiple-columns/:“Craig Lotter” has a great post about identifying columns. For now, my sql looks like:
SELECT twitter_id
FROM tweets
GROUP BY twitter_id
HAVING (COUNT(twitter_id) > 1);
And from there, I just do something like this in some Ruby framework because I still suck at SQL. More elegant solutions must exist – I just don’t know them.
bad_ids = ActiveRecord::Base.connection.execute(
"SELECT twitter_id FROM tweets GROUP BY twitter_id HAVING (COUNT(twitter_id) > 1);"
)
Tweet.all(:twitter_id => bad_ids).collect{|t| t.destroy}