Follow Along as I Stumble on the Path to Learning RoR

Posts tagged “sql

Selecting Last Records from Table

I needed to select the last records in a table.  I could do a MySQL query with no limit on records, but that could be inefficient.  Instead you could and this to the end of your MySQL query:

order by id desc limit x

For example:

SELECT * FROM articles order by id desc limit 5

This will return the last five records in the table.


Rails Datatypes





Shows Rails data types, also maps to SQL datatypes