Limit the number of rows returned

Source: Internet
Author: User

To create a test table:

CREATE OR REPLACE VIEW V asselect ' a ' as C from Dualunion Allselect ' B ' as C from Dualunion Allselect ' C ' as C from Dualun ION Allselect ' d ' as C from Dualunion Allselect ' E ' as C from dual; SELECT * from V;

If you want to query the first two data, you can use pseudo-column rownum to complete:

SELECT C from v WHERE ROWNUM < 3;

The query results are as follows:

What happens if you query directly with rownum = secondly?

SELECT C from v WHERE ROWNUM = 2;

The query results are as follows:

This is because rownum is a pseudo-column added to the result set, that is, the result set is followed by a column (emphasis: first, the result set). It always starts at 1. So your chosen result cannot be no more than 1, and there are other values greater than 1.

The correct query statement should look like this, Sir, into the serial number:

Select C from (select ROWNUM as No, C from v) WHERE no = 2;

The query results are as follows:

Limit the number of rows returned

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.