A
A
Alexander Koshelev2018-09-15 19:45:35
PostgreSQL
Alexander Koshelev, 2018-09-15 19:45:35

How to change the display (newer ones first) to data pages from the database?

Good afternoon everyone, I noticed a very upsetting fact, my data is displayed first old then new, I would like to change the display order, that is, the data that appeared in the database (those with id greater in value) were displayed on top.
Here is my code (simplified as much as possible, but the essence is the same)
ejs file

<% for(var i = 0; i < result.length; i++) {%>
    <div><%=result[i].dataValues.username%></div><br>
   <%}%>

файл роута
router.get('/index',  (req, res) => {
  let result = User.findAll({
    offset: 0, limit: 10
  }).then(result => {
    res.render('index', {result: result});
    console.log(result);
  })

database file
const User = db.define('table', {
  id: {
    type: Sequelize.INTEGER,
    autoIncrement: true,
    primaryKey: true,
  },
  username: {
    type: Sequelize.STRING(254)
  },
});

Prompt very much I ask how to change the order of display of the data! Everything works, everything is displayed by my code but not in the right order, it is necessary that the most recent data rows be at the top and not at the bottom!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-09-15
@Xandr24

Have you tried opening the documentation ?
Well, in general, it would be useful to get acquainted with at least the basics of SQL, so that solving such issues on your own would not cause difficulties, at least you will know what to look for.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question