Modify SQL in messages controller