How do I count number of rows in a table in mysql ?

  • dann123
  • Novice
  • Novice
  • dann123
  • Posts: 17

Post 3+ Months Ago

I want to know how can we count no. of rows in a given table through a single query if there is no candidate key?
And how do I retrieve last ten rows using another query ?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

You can use the COUNT function in the select field for finding total rows, and for returning that last 10 rows you can use LIMIT.

Code: [ Select ]
SELECT COUNT(*) FROM table

Code: [ Select ]
SELECT * FROM table ORDER BY field LIMIT 10


For the last one field is some value that has an order to it, such as an ID or insert time.
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

SQL Code: [ Select ]
SELECT * FROM `table` ORDER BY `field` DESC LIMIT 10


DESC for the last 10
ASC for the first 10

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 109 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.