六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 109|回复: 0

Returning TOP N Records

[复制链接]

升级  6%

15

主题

15

主题

15

主题

秀才

Rank: 2

积分
59
 楼主| 发表于 2013-1-12 16:31:53 | 显示全部楼层 |阅读模式
 
Returning TOP N Records

<div class="entryBody">Returning only the first N records in a SQL query differs quite a bit between database platforms.
 Here's some samples:
Microsoft SQL Server
SELECT TOP 10 column FROM tablePostgreSQL and MySQL
SELECT column FROM tableLIMIT 10Oracle
SELECT column FROM tableWHERE ROWNUM <= 10Sybase
SET rowcount 10SELECT column FROM tableFirebird
SELECT FIRST 10 column FROM tableDue to these differences if you want to keep your code database independent you should use the maxrows attribute in the cfquerytag in ColdFusion. The tradeoffs to database independance isperformance, I would expect maxrows to be slower than specifying therows in the SQL.
<cfquery datasource="#ds#" maxrows="10">SELECT column FROM table</cfquery>PostgreSQL and MySQL have a cool feature that will let you return anarbitrary range of rows (eg return rows 10-20). This is very handy fordisplaying pages of records:
SELECT column FROM tableLIMIT 10 OFFSET 20The above query will return rows 20-30
 
 
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表