Add the SQL & amp; MySQL query field as the row number

Source: Internet
Author: User


SQL & MySQL query adds a field as the row number. SQL: select row_number () over (order by col desc), * from table; the function "row_number" must have an OVER clause using ORDER, the automatic values are arranged by the field col: www.2cto.com MySQL: SET @ r = 0; SELECT @ r: = IFNULL (@ r, 0) + 1 AS rownum, table. * FROM table order by col DESC; Unlike SQL, fields are added to the loop. If you want to query all rows, you must add the table name table. *, if a field is obtained, it is not required, col1, col2...

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.