SQL statement for mysql, Oracle, and mssql to retrieve the first few pieces of data

Source: Internet
Author: User
The following describes how to write SQL statements for mysqlOraclemssql to retrieve the first few pieces of data. For more information, see.

The following describes how to write SQL statements for mysql/Oracle/mssql to retrieve the first few pieces of data. If you need them, refer to them.

The following describes how to write SQL statements for mysql/Oracle/mssql to retrieve the first few pieces of data. If you need them, refer to them.

If you use this statement in ms sqlserver:

The Code is as follows:

Select top 2 * from test01


Oracle statement:

The Code is as follows:

Select * from (select rownum r, * from test) ttwhere tt. r> 50 and tt. r <= 100;

(It is best to use PLSQL cursor to solve this problem)


In DB2:

The Code is as follows:
Select * from payment fetch first 5 row only -- query the first 5 Records

MSSQL

If you use this statement in ms sqlserver:

The Code is as follows:
Select top 2 * from test01

Only the first two records are displayed,

MYSQL can use limit.

The Code is as follows:
Select * from your_table where... limit 2;



One msssql instance

1. Use ms SQL Server 2008;
2. The database content is as follows: Zhang San mathematics 98 Li Si mathematics 95 Wang Wu mathematics 90 Zhao Liu English 100 Zhang San English 99 Li Si English 69
3. results to be queried: the first two of each course

The Code is as follows:

Select. xingming,. kemu,. fenshu from xuexi a where. fenshu in (SELECT top 2 fenshu FROM xuexi WHERE xingming =. xingming and kemu =. kemu order by fenshu desc)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.