Home > Backend Development > PHP Tutorial > Database query statement

Database query statement

WBOY
Release: 2016-08-08 09:06:57
Original
922 people have browsed it

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

Reply content:

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

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template