MySQL adds serial numbers to query results

Source: Internet
Author: User

set @rownum =0;        Select  @rownum: [Email protected]+1 as from table1
: What is the difference between = and =?
    1. "=", only when set and update are the same as: =, the function of the assignment, the other is equal to the role. In view of this, the use of variables to implement line numbers must be used: =
    2. ": =", the function of assigning values not only in set and update, but also in select.

If you understand the difference between = and: =, then you understand the phenomenon below.

@num: [Email protected]+1,:= is the function of assignment, so the @num+1 is executed first and then assigned to @num, so the function of line number can be implemented correctly.

@[email protected]+1, at this time = is equal to the role, @num not equal to @num+1, so always return 0, if changed to @[email protected], always return 1. MySQL database, with 1 for true, 0 for false.

MySQL adds serial numbers to query results

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.