From the course: Ruby on Rails 5 Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Query methods: Order, limit,  and offset

Query methods: Order, limit, and offset - Ruby on Rails Tutorial

From the course: Ruby on Rails 5 Essential Training

Start my 1-month free trial

Query methods: Order, limit, and offset

- [Instructor] We've seen how to specify the conditions for our query, how to retrieve only the records that match a certain criteria, but there are three additional query methods that are helpful in allowing us to find exactly the records we want, and those are order, limit, and offset. Order is going to specify the sort order of the returned records. We can sort the records by any column, ID, name, position, created at, etc. We can sort them alphabetically, or reverse alphabetically, ascending, or descending, chronologically, or reverse chronologically. Limit will limit the results that are returned. This becomes especially important when there are a lot of records which match our conditions. Let's imagine that we have a database of 20,000 customers. We wouldn't want to see a page with all 20,000 customers at one time, we'd probably want to view them broken up as pages, maybe just 20 at a time. In that case, we would limit the results to 20. If we then wanted to view page 51 of…

Contents