Ask for a simple SQL

Source: Internet
Author: User
Ask for 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 = 126300 limit 1) %'
What are the SQL errors? 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 limit 1)
In this way, a search result is returned.

Note: the subquery is correct. the returned result of the subquery is IE0384701.
Goods_sn is of the varchar data type.


Reply to discussion (solution)

What do I mean by adding %?

No error
But I will never believe that your table has a string like (select left (goods_sn, 9) as goods_sn from eload_goods where goods_id = 126300 limit 1 )...

No error
But I will never believe that your table has a string like (select left (goods_sn, 9) as goods_sn from eload_goods where goods_id = 126300 limit 1 )...

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 (LEFT (goods_sn, 9), '%') AS goods_sn FROM eload_goods WHERE goods_id = 126300 LIMIT 1)

Where am I wrong?
Select * from eload_goods where goods_sn like '(select left (goods_sn, 9) as goods_sn from eload_goods where goods_id = 126300 limit 1) %'
Do you know the string?

SELECT * FROM eload_goods WHERE goods_sn LIKE (select concat (LEFT (goods_sn, 9), '%') AS goods_sn FROM eload_goods WHERE goods_id = 126300 LIMIT 1)

Isn't this SQL easy?

Where am I wrong?
Select * from eload_goods where goods_sn like '(select left (goods_sn, 9) as goods_sn from eload_goods where goods_id = 126300 limit 1) %'
Do you know the string?

MYSQL subqueries do not support limit. it should be an error caused by limit 1.
If goods_id is the primary key, limit 1 is completely unnecessary and not supported

The error is caused by single quotes. the content in single quotes is not searched, but the content of the single quotes is directly matched.

SELECT * FROM eload_goods WHERE goods_sn LIKE (select concat (LEFT (goods_sn, 9), '%') AS goods_sn FROM eload_goods WHERE goods_id = 126300 LIMIT 1)

Isn't this SQL easy?

How can I write better?

Where am I wrong?
Select * from eload_goods where goods_sn like '(select left (goods_sn, 9) as goods_sn from eload_goods where goods_id = 126300 limit 1) %'
Do you know the string?

I understand what you mean. 'Select... 'is a string, so I am asking for a solution.

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.