I am looking for a way to create a query that compares two attributes of the same record, without first pulling the record and comparing post-query. In my particular case, there will potentially be 10 thousand notes, so repeating each of them is not an option.
Example: searching for this record by query. where updated_at == created_at
#<User id: 1, name: "xxx", created_at: "2012-07-01 12:00:00", updated_at: "2012-07-01 12:00:00">
Rails 3+, ActiveRecord, MySQL.
Update. As the Matzi commentator notes, when using sqlite, the following is valid: mysql :
User.where("created_at == updated_at")
Solved : simple error, ruby vs sql.
Sqlite can use:
User.where("created_at == updated_at")
but MySQL requires:
User.where("created_at = updated_at")
Joe
source share