Incorrect mysql Query Results

Source: Internet
Author: User
Most of my order queries are based on the first SQL statement, and the query order results are unique. However, there are two query results in this order. why? Under normal circumstances, the field attribute is a string. is the value the same without quotation marks? Please...

Most of my order queries are based on the first SQL statement, and the query order results are unique. However, there are two query results in this order. why? Under normal circumstances, the field attribute is a string. is the value the same without quotation marks? Please advise

Query results using the first SQL statement

Reply content:

Most of my order queries are based on the first SQL statement, and the query order results are unique. However, there are two query results in this order. why? Under normal circumstances, the field attribute is a string. is the value the same without quotation marks? Please advise

Query results using the first SQL statement

Of course, it is different. mysql will perform implicit type conversion. when comparing numbers and varchar, mysql will convert varchar to numbers. if the password type is a string, if the query condition is int 0, it will match.show warnings;View

I'm also curious to post your query results.

How many bits does your varchar have? is it automatically ignored because it is not long enough?

Out_trade_no, are all numeric characters, right? It may be that the value is too large. When implicit type conversion is performed, a part of the data is intercepted, resulting in a match. this reminds you of precautions for writing SQL statements, the string data type should be enclosed in quotation marks to avoid unnecessary vulnerabilities.

Varchar to numeric truncation.
Without quotation marks, mysql scans the entire table first, and converts the queried results into numbers using varchar.
If the single quotation mark type is matched, index scanning is used directly (if the column has an index ).
Therefore, without quotation marks, performance problems may occur.

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.