SELECT goods_name
FROM ecs_goods
WHERE cat_id
IN ('9','10','12','13','14') AND goods_name
LIKE '%3%'
Please point out the problem
What is the correct format and ask a master
SELECT goods_name
FROM ecs_goods
WHERE cat_id
IN ('9','10','12','13','14') AND goods_name
LIKE '%3%'
Please point out the problem
What is the correct format and ask a master
The format is correct, what is the issue?
This statement is correct.
There is no problem with the statement, but as long as the amount of data is a little larger, it will be extremely slow, and the only optimization point is to add an index to cat_id. But if you guessed it correctly, this field is a categorical field with repeated values, so adding an index is of no use.
If there are a lot of SQLs like this, it is recommended to use a retrieval system, Elastic search or Solr.
SELECT goods_name FROM ecs_goods WHERE (cat_id = '9'or cat_id ='10' or cat_id ='12' or cat_id ='13' or cat_id ='14') AND goods_name LIKE '%3%'
It is best not to use it in
Because the two conditions are and, you can execute them separately. First in, and then like from the result, it should be possible