SELECT TOP - Rudi Grobler

SELECT TOP

It is a real pain in the ... that every sql server uses it's own select top equivelent... Here follows a list of some of the ones I found:

SQL Server: SELECT TOP 10 * FROM [TABLE]
DB2: SELECT * FROM [TABLE] FETCH FIRST 10 ROWS ONLY
PostgreSQL: SELECT * FROM [TABLE] LIMIT 10
Oracle: SELECT * FROM [TABLE] WHERE ROWNUM <= 10
Sybase: SET ROWCOUNT 10 SELECT * FROM [TABLE]
Firebird: SELECT FIRST 10 * FROM [TABLE]
MySQL: SELECT * FROM [TABLE] LIMIT 10

I haven't tested all of these... I only needed the SQL Server and MySQL statements but will supply the rest as reference!!!

Published Thursday, September 20, 2007 9:20 AM by rudi

Comments

# SELECT TOP Statements

You've been kicked (a good thing) - Trackback from DotNetKicks.com

Thursday, September 20, 2007 9:27 AM by DotNetKicks.com

# re: SELECT TOP

I know SQL Server also supports the SET ROWCOUNT n  syntax but if I recall correctly it limits the joins as well.

Thursday, September 20, 2007 11:59 AM by Craig Nicholson

# re: SELECT TOP

Yes,

The basic syntax is:

SET ROWCOUNT 10

SELECT * FROM [TABLE]

It is however recomended to rather use TOP 10

SET ROWCOUNT statement limits the number of record returned to the client during a single connection.

Thursday, September 20, 2007 12:13 PM by rudi

# Is Local Lekker?

I am currently sitting at Cape Town airport and as usual our flight is delayed, so I decided to use this

Friday, February 22, 2008 7:13 AM by Rudi Grobler

# db2 select not in

Pingback from  db2 select not in

Friday, May 02, 2008 11:35 PM by db2 select not in