Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Select (SQL)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Non-standard syntax === Some DBMSs offer non-standard syntax either instead of or in addition to SQL standard syntax. Below, variants of the ''simple limit'' query for different DBMSes are listed: {|class="wikitable" |- | <syntaxhighlight lang="tsql" highlight="1">SET ROWCOUNT 10 SELECT * FROM T</syntaxhighlight> | [[Microsoft SQL Server|MS SQL Server]] (This also works on Microsoft SQL Server 6.5 while the '''Select top 10 * from T''' does not) |- | <syntaxhighlight lang="postgres" highlight="2">SELECT * FROM T LIMIT 10 OFFSET 20</syntaxhighlight> | [[Netezza]], [[MySQL]], [[MariaDB]] (also supports the standard version, since version 10.6), [[SQL Anywhere|SAP SQL Anywhere]], [[PostgreSQL]] (also supports the standard, since version 8.4), [[SQLite]], [[HSQLDB]], [[H2 (DBMS)|H2]], [[Vertica]], [[Polyhedra DBMS|Polyhedra]], [[Couchbase Server]], [[Snowflake Computing]], [[Virtuoso Universal Server|OpenLink Virtuoso]] |- | <syntaxhighlight lang="sql" highlight="2">SELECT * from T WHERE ROWNUM <= 10</syntaxhighlight> | [[Oracle database|Oracle]] |- | <code>SELECT '''FIRST 10''' * from T </code> | [[Ingres (database)|Ingres]] |- | <code>SELECT '''FIRST 10''' * FROM T order by a </code> | [[IBM Informix|Informix]] |- | <code>SELECT '''SKIP 20 FIRST 10''' * FROM T order by c, d </code> | [[IBM Informix|Informix]] (row numbers are filtered after order by is evaluated. SKIP clause was introduced in a v10.00.xC4 fixpack) |- | <code>SELECT '''TOP 10''' * FROM T</code> | [[Microsoft SQL Server|MS SQL Server]], [[Adaptive Server Enterprise|SAP ASE]], [[Microsoft Access|MS Access]], [[SAP IQ]], [[Teradata]] |- | <syntaxhighlight lang="sql" highlight="2">SELECT * FROM T SAMPLE 10</syntaxhighlight> | [[Teradata]] |- | <code>SELECT '''TOP 20, 10''' * FROM T</code> | [[Virtuoso Universal Server|OpenLink Virtuoso]] (skips 20, delivers next 10)<ref name="docs_9.19">{{Cite web |title=9.19.10. The TOP SELECT Option |author=OpenLink Software |work=docs.openlinksw.com |access-date=1 October 2019 |url= http://docs.openlinksw.com/virtuoso/topselectoption/ |language=en-US}}</ref> |- | <code>SELECT '''TOP 10 START AT 20''' * FROM T</code> | [[SQL Anywhere|SAP SQL Anywhere]] (also supports the standard, since version 9.0.1) |- | <code>SELECT '''FIRST 10 SKIP 20''' * FROM T</code> | [[Firebird (database server)|Firebird]] |- | <syntaxhighlight lang="sql" highlight="2">SELECT * FROM T ROWS 20 TO 30</syntaxhighlight> | [[Firebird (database server)|Firebird]] (since version 2.1) |- | <syntaxhighlight lang="sql" highlight="2">SELECT * FROM T WHERE ID_T > 10 FETCH FIRST 10 ROWS ONLY</syntaxhighlight> | [[IBM Db2]] |- | <syntaxhighlight lang="sql" highlight="2">SELECT * FROM T WHERE ID_T > 20 FETCH FIRST 10 ROWS ONLY</syntaxhighlight> | [[IBM Db2]] (new rows are filtered after comparing with key column of table T) |}
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)