Hi,
I have an Adverts table with a created_at column. I would like to get
back the 3 newest adverts. How would I do this.
Thanks
David
Hi,
I have an Adverts table with a created_at column. I would like to get
back the 3 newest adverts. How would I do this.
Thanks
David
david wrote:
I have an Adverts table with a created_at column. I would like to get
back the 3 newest adverts. How would I do this.
This depends on what you’re using, but it’s a relatively simple SQL
statement:
SELECT *
FROM adverts
ORDER BY created_at DESC
LIMIT 3;
Are you using DBI? Straight SQL? ActiveRecord? Og?
Pistos
Pistos C. wrote:
david wrote:
I have an Adverts table with a created_at column. I would like to get
back the 3 newest adverts. How would I do this.This depends on what you’re using, but it’s a relatively simple SQL
statement:SELECT *
FROM adverts
ORDER BY created_at DESC
LIMIT 3;Are you using DBI? Straight SQL? ActiveRecord? Og?
Pistos
ActiveRecord
david wrote:
Pistos C. wrote:
david wrote:
I have an Adverts table with a created_at column. I would like to get
back the 3 newest adverts. How would I do this.This depends on what you’re using, but it’s a relatively simple SQL
statement:SELECT *
FROM adverts
ORDER BY created_at DESC
LIMIT 3;Are you using DBI? Straight SQL? ActiveRecord? Og?
Pistos
ActiveRecord
find(:all, :limit => 3, :order => ‘created_at DESC’)
Check out the Rails mailing list, it would be better to ask these sort
of questions there.
use SQL of
SELECT * FROM Adverts ORDER BY created_at DESC LIMIT = 3;
Advert.find(:all, :order => “created_at DESC”, :limit => 3)
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs