FlerrElectronics
FlerrElectronics

Reputation: 291

Retrieving the newest X amount of entries in a MySQL database, with Node-MYSQL?

I am able to retrieve the latest entry in node-mysql with:

connection.query('SELECT * FROM NewsV2 ORDER BY IDCode DESC LIMIT 1',  
  function(err, rows, fields) {}

But, I would like to retrieve the latest say ten entries, how can I achieve this?

Upvotes: 0

Views: 24

Answers (1)

blamb
blamb

Reputation: 4299

If you have a column for date, you would add that to the query ORDER BY IDCode DESC Date DESC and if you want 10, change the limit like so: LIMIT 10.

If IDCode isn't the id col, and you happen to be adding new rows at a time, you can also add the sort ORDER BY ID DESC but I'll guess your IDCode is your ID field.

Upvotes: 0

Related Questions