How to query n records in mysqloraclesqlserver

Source: Internet
Author: User
Welcome to the Oracle community forum and interact with 2 million technical staff to access the MySQL oraclesqlserver Method for querying n records of Data SELECT * FROMtableLIMIT5; select * fromissu_infolimit0, 6Limit0, 6 which is correct, show the first 6 select * fromissu_infolimit7, 6; Limit7, 6

Welcome to the Oracle community forum and interact with 2 million technical staff> go to mysql oracle sqlserver to query n records. SELECT * FROM table LIMIT 5; select * from issu_info limit, 6 Limit is correct. The first 6 select * from issu_info limit; Limit is displayed.

Welcome to the Oracle community forum and interact with 2 million technical staff> enter

How to query n records in mysql oracle sqlserver

SELECT * FROM table LIMIT 5;

Select * from issu_info limit 0, 6

Limit 0, 6

This is correct. The first six items are displayed.

Select * from issu_info limit 7, 6;

Limit 7, 6

Take from 8th, take 6

Select * from table order by rand () limit 1

This is to randomly select a record. If you want to extract multiple records, change 1 to the number you want to Top.

Using a feature of the select statement in mysql, you can easily implement paging of query results. The syntax of the select statement is as follows:

SELECT [STRAIGHT_JOIN] [SQL _SMALL_RESULT] [SQL _BIG_RESULT] [HIGH_PRIORITY]

[DISTINCT | DISTINCTROW | ALL]

Select_expression ,...

[Into outfile 'file _ name' export_options]

[FROM table_references

[WHERE where_definition]

[Group by col_name,…]

[HAVING where_definition]

[Order by {unsigned_integer | col_name | formula} [ASC | DESC],…]

[LIMIT [offset,] rows]

[PROCEDURE procedure_name]

The LIMIT clause can be used to LIMIT the number of data returned by the SELECT statement. It has one or two parameters. If two parameters are provided,

The first parameter specifies the position of the first row returned in all data, starting from 0 (note not 1). The second parameter specifies the maximum number of returned rows.

Number. For example:

Select * from table LIMIT 5, 10; # return data in rows 6-15

Select * from table LIMIT 5; # Return the first five rows

Select * from table LIMIT; # Return the first five rows

SQL statements used to query the first few records in different databases: 261. ORACLE

SELECT * FROM TABLE1 where rownum <= N

2. INFORMIX

Select first n * FROM TABLE1

3. DB2

SELECT * ROW_NUMBER () OVER (order by COL1 DESC) as rownum where rownum <= N

Or

SELECT COLUMN FROM TABLE FETCH FIRST N ROWS ONLY

4. SQL SERVER

Select top n * FROM TABLE1

5. SYBASE

SET ROWCOUNT N

GO

SELECT * FROM TABLE1

6. MYSQL

SELECT * FROM TABLE1 LIMIT N

7. FOXPRO

SELECT * TOP N FROM TABLE ORDER BY COLUMN

8. query the first few SQL records in postgres

SELECT * FROM TABLE LIMIT

Select id from mytable order by update_date desc limit 0, 3;

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.