Welcome to Sol 3 Sign in | Join | Help
CS Search | Live Search Search

Sol 3

Home of Barrows Software Solutions, LLC

Keith Barrows

Subjects range from Personal to Technical.

SELECT TOP [x] Records

When you use one database platform long enough you start to think everything you do is ANSI SQL-92 compliant.  Until you switch database platforms that is!  Then you find the simple things no longer work.  Take for example the TOP clause used so often in MS SQL Server.  It does not work on Oracle.  <sigh/>

I've been digging into Oracle lately and am noting down the differences in the hopes it will help someone else down the road.  So, without further waiting, here are the examples to get the top 10 records for the different platforms:

  • MS SQL Server
    SELECT TOP 10 *
      FROM [table]
  • Oracle
    SELECT *
      FROM [table]
     WHERE rownum <= 10;
  • MySql
    SELECT *
      FROM [table]
     LIMIT 10
  • DB2
    SELECT *
      FROM [table]
     FETCH FIRST 10 ROWS ONLY;
Hope that helps someone out.  Smile
Published Tuesday, April 10, 2007 9:16 AM by Keith Barrows
Filed under: , ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
(optional)
(required) 
Submit

About Keith Barrows

I've been in computing since 1975. I started on an old PDP-8J with 3k of memory and 2 teletypes. I learned BASIC and Octal based assembly. I later moved into CPM, TR-DOS, Apple and finally into PC-DOS, Dr DOS and MS-DOS. I've been a beta tester for over a decade, got into web applications as a means to handle B2B requirements and have specialized in data movement between applications and businesses since. I have been a MVP, ASP Elite and was selected by Microsoft as one of the original 15 board members for ASPInsiders.
CS Build: 2.1.61129.2
1999
Listed on the CS Listings Powered By Community Server Themed by nb development