Order + find query

Hi,
I have got a table which has many field, one of them is updated_at.

Can anybody tell me how to get the value of a row which has been updated
recently.

-Thanks

Saurav

I have written this query for my existing table Status. Its working
fine.

Status.find_by_sql(“select * from statuses where document_id
=’#{self.id}’ and status=‘REVIEWED’ and updated_at = ( select
max(updated_at) from statuses)”)

Can anybody suggest how can i write it using only the find method in
rails ?

-Saurav

Saurav C. wrote:

Hi,
I have got a table which has many field, one of them is updated_at.

Can anybody tell me how to get the value of a row which has been updated
recently.

-Thanks

Saurav

Saurav C. wrote:

I have written this query for my existing table Status. Its working
fine.

Status.find_by_sql(“select * from statuses where document_id
=’#{self.id}’ and status=‘REVIEWED’ and updated_at = ( select
max(updated_at) from statuses)”)

@status = Status.find(:all, :conditions => [‘document_id = ? and status
= ? and updated_at = (select max(updated_at) from statuses)’, self.id,
‘REVIEWED’]

I have no way to test it, but I think that would be the way to do it.

-S

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs