Select top of Access Database

Source: Internet
Author: User

I have never encountered the select top problem in the ACCESS database before. Today I have encountered this problem.

Example: Select top 6 ID, title from table where ispass = 1 order by orderid

In the previous statement, only 6 data records are returned. After updating some data records, more than 6 data records are returned.

Changed to: Select top 6 ID, title from table where ispass = 1 order by ID

Then, only 6 results are returned. After checking the information, you can find the problem: the orderid of the sorting field has the same record, whileTop predicates are not selected in the same value (top cannot select the top order you want from the same value).

Corrected SQL statement: Select top 6 ID, title from table where ispass = 1 order by orderid, Id DESC

Done!

 

Conclusion: When the select top statement is used in access, the sorted field values cannot be repeated. If records with the same value exist, corresponding records are returned in this statement. Solution: Add a sorting field.

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.