Ask for a simple SQL

Source: Internet
Author: User
Ask a simple sql:

SELECT * from Eload_goods where goods_sn like ' (select Left (goods_sn,9) as goods_sn from eload_goods where goods_id = 1263 XX limit 1)% '
What's wrong with this SQL? No results found.

SELECT * from eload_goods where goods_sn = (select Left (goods_sn,9) as goods_sn from eload_goods where goods_id = 126300 l Imit 1)
There is a result in this search.

Note: The subquery is correct. The subquery returns the result: IE0384701
GOODS_SN is a varchar data type


Reply to discussion (solution)

What do you mean by adding a%?

Nothing wrong.
But I'm not going to believe it. (select Left (goods_sn,9) as goods_sn from eload_goods where goods_id = 126300 limit 1) ... Such a string

Nothing wrong.
But I'm not going to believe it. (select Left (goods_sn,9) as goods_sn from eload_goods where goods_id = 126300 limit 1) ... Such a string

Moderator, you are wrong.
(select Left (goods_sn,9) as goods_sn from eload_goods where goods_id = 126300 limit 1) is absolutely correct. There are also such strings.

The problem has been solved and the answer is attached:
SELECT * from Eload_goods where GOODS_SN like (SELECT CONCAT (goods_sn,9), '% ') as goods_sn from Eload_goods where good s_id = 126300 LIMIT 1)

Where was I wrong?
SELECT * from Eload_goods where goods_sn like ' (select Left (goods_sn,9) as goods_sn from eload_goods where goods_id = 1263 XX limit 1)% '
Don't know the string?

SELECT * from Eload_goods where GOODS_SN like (SELECT CONCAT (goods_sn,9), '% ') as goods_sn from Eload_goods where good s_id = 126300 LIMIT 1)

Does this kind of SQL do not have the egg ache?

Where was I wrong?
SELECT * from Eload_goods where goods_sn like ' (select Left (goods_sn,9) as goods_sn from eload_goods where goods_id = 1263 XX limit 1)% '
Don't know the string?

MySQL sub-query does not support limit, should be limit 1 caused by the error bar
If GOODS_ID is the primary key, limit 1 is completely unnecessary and is not supported

The reason for the error is that the single quotation marks, the contents of the single quotation mark are not searched, but the quotation mark content area is directly matched.

SELECT * from Eload_goods where GOODS_SN like (SELECT CONCAT (goods_sn,9), '% ') as goods_sn from Eload_goods where good s_id = 126300 LIMIT 1)

Does this kind of SQL do not have the egg ache?

How can I write better?

Where was I wrong?
SELECT * from Eload_goods where goods_sn like ' (select Left (goods_sn,9) as goods_sn from eload_goods where goods_id = 1263 XX limit 1)% '
Don't know the string?

I understand what you mean, ' Select ... ' is a string, so I am to ask for a solution to the wording.

  • 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.