Noah Noah - 1 year ago 212
Javascript Question

Sequelize findOne latest entry

I need to find the latest entry in a table. What is the best way to do this? The table has Sequelize's default


Answer Source

Method findOne is wrapper for findAll method. Therefore you can simply use findAll with limit 1 and order by id descending.


  limit: 1,
  where: {
    //your where conditions, or without them if you need ANY entry
  order: [ [ 'createdAt', 'DESC' ]]
  //only difference is that you get users list limited to 1
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download