WeCodeThings Library
Library of code bits
Glossary    Contact Us
Need a web designer? visit WeCodeThings.Com for more details
Search  
   
Browse by Category


WeCodeThings Library .: SQL .: mySQL SQL Select the last 50 rows inserted into the database by using LIMIT



mySQL SQL Select the last 50 rows inserted into the database by using LIMIT

In mySQL you can show a specific number of rows you would like to see by using the LIMIT clause. If you use LIMIT 0, 50 then it will return the first 50 rows, but if you have 14,500 records in a database, then you could use LIMIT 14450, 14500 and you will see that last 50 rows inserted into the database.  Here's an example, I have 550 records in a database and I want to see the last 50:

  1. SELECT a.pkid, a.call_id, a.log_cmpid, a.call_group, a.call_account, a.forwardno, a.callerno, a.caller_name, a.call_start, a.call_end, a.call_status, a.dispo, a.rating, a.revenue, a.assigned_to, a.ring_duration, a.answer_offset, a.inbound_ext, b.cmpname, b.cmpdescr, b.called_number, c.grpname, c.grpdescr, e.retname
  2. FROM TBLcall_log a
  3. LEFT OUTER JOIN TBLcall_cmp b ON b.cmpid = a.log_cmpid
  4. LEFT OUTER JOIN TBLcall_group c ON c.grpid = b.cmpgrpid
  5. LEFT OUTER JOIN TBLcall_account d ON d.accid = c.grpaccid
  6. LEFT OUTER JOIN TBLretailer e ON e.retailerID = d.retailerID
  7. WHERE 0=0
  8. LIMIT 500, 550 

 

If you need to do this by using something other than mySQL, then W3Schools has a great article here:
http://www.w3schools.com/Sql/sql_top.asp



How helpful was this article to you?

Related Articles

article PHP Simple MySQL Open Configure and Close the Connection to a Database using PHP
Usually you want to create a “config.php”...

(No rating)  5-5-2009    Views: 751   
article PHP Simple Insert Into MySQL Database using isset function $_POST
To insert an item into the database, you...

(No rating)  5-8-2009    Views: 1396   
article SQL Sum a Sum MS SQL Server, Oracle, MySQL Sum a Group By
SQL SUM A SUM For some reason, this was...

(No rating)  11-24-2009    Views: 832   

User Comments

Add Comment
No comments have been posted.




.: Powered by Lore .:Code by WeCodeThings Website Design and Development