Data SQL for the first n rows of each database query

Source: Internet
Author: User
Tags sybase database

1. Oracle Database
SELECT * from TABLENAME WHERE ROWNUM <= N
2. Infomix Database
SELECT First N * from TABLENAME
3. DB2 Database
SELECT *
From (SELECT * row_number () + ({ORDER by COL1 DESC}) as ROWNUM from TABLENAME)
WHERE ROWNUM <= N
Or
SELECT COLUMN from TABLENAME FETCH first N ROWS only
4. SQL Server Database
SELECT TOP N * from TABLENAME
5. Sybase database
SET ROWCOUNT N
GO
SELECT * from TABLENAME
6. mysql Database
SELECT * from TABLENAME LIMIT N

2 DB2
Select column from [TableName] where [query condition] FETCH first all rows only
3 MySQL
SELECT * FROM [tableName] where [query condition] limit 10
4 SQL Server
4.1 Read the first 10 strips
Select Top (Ten) * from [tableName] where [query condition]
4.2 After reading 10 strips
Select Top * FROM [TableName] ORDER by id DESC
4.3 According to a sort, 5th to 10th of these records
Select Top 6 * from [tableName] where ID not in (select top 4 ID from [TableName])
5 Oracle
SELECT * FROM [TableName] where rownum<=10
Oracle queries data for rows 10th through 100th
SELECT * FROM (select T.*,rownum as RN from table_name T) where RN between and 100;

1. Is the value of the field in the Oracle lookup table empty?
SELECT * FROM table_name where field name is (not) null;
2. Find whether a field in a table is a value
SELECT * FROM table_name where field name = ' field value ';
3. Change the original value of the field in the table to a new value
Update table_name SET Field name = ' new field value ' where field name = ' Old field value '

Data SQL for the first n rows of each database query

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.