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.