SQL & amp; MySQL Query add field as row number _ MySQL

Source: Internet
Author: User
SQLamp; amp; MySQL Query adds a field as the row number bitsCN.com


Add a field for SQL & MySQL Query as a row number

SQL:

Select row_number () over (order by col desc), * from table;

The "row_number" function must have an OVER clause using order by, which is sorted BY the field col.

Automatic column values

MySQL:

SET @ r = 0;

SELECT @ r: = IFNULL (@ r, 0) + 1 AS rownum, table. * FROM table order by col DESC;

Different from SQL, add fields to the Loop. if you want to query all rows, you must add the table name table. *.

Field is not required, col1, col2...

BitsCN.com

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.