开发者

Find last order limit

<% Specimen.find(:all, :order => 'distribution_sheet_id', :limit => 10).each do |df| 开发者_JAVA技巧%>
  <%= df.id %>
<% end %>

This gives this query:

SELECT * FROM "specimens" ORDER BY distribution_sheet_id LIMIT 10

I need this:

SELECT * FROM "specimens" ORDER BY distribution_sheet_id DESC LIMIT 10

I'm using Rails < 3. Any help please?


Add DESC to the end of your order value.

Specimen.find(:all, :order => 'distribution_sheet_id DESC', :limit => 10)

Full example:

<% Specimen.find(:all, :order => 'distribution_sheet_id DESC', :limit => 10).each do |df| %>
  <%= df.id %>
<% end %>


Just add DESC

Specimen.find(:all, :order => 'distribution_sheet_id DESC', :limit => 10).each do |df| %> <%= df.id


Specimen.
  all(:order => 'distribution_sheet_id DESC', :limit => 10, :select => :id).
  map(:&id)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜