Mysql/oracle/mssql to take the first few data SQL writing

Source: Internet
Author: User
Tags mssql

If you use this statement in MS SQL Server:

The code is as follows Copy Code

Select Top 2 * from test01


Oracle's statement:

The code is as follows Copy Code

SELECT * FROM (select RowNum r, * from test) Ttwhere TT.R > and TT.R <= 100;

(preferably with a plsql cursor)


In DB2:

The code is as follows Copy Code
SELECT * FROM payment to fetch first 5 row only--check the top 5 records

MSSQL

If you use this statement in MS SQL Server:

The code is as follows Copy Code
Select Top 2 * from test01

Only the first 2 records will be displayed,

MYSQL to use limit on it.

The code is as follows Copy Code
SELECT * from your_table where ... limit 2;



Msssql an instance

1. Use of MS SQL Server 2008;
2. The database contents are as follows: John Mathematics 98 Dick Mathematics 95 Harry Mathematics 90 Zhao Six English 100 Zhang three English 99 Li four English 69
3. Results to query: Top 2 of each course

  code is as follows copy code

Select A.xingming,a.kemu,a.fenshu from Xuexi a where A.fenshu in (SELECT top 2 Fenshu from Xuexi where xingming = a.xingming and Kemu=a.kemu ORDER BY Fenshu Desc)

Related Article

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.