How to check if a character set exists in the table column?

Asked

Viewed 51 times

-1

I have the following table:

|id|nome                 |
|1 |Lucas Santos da Silva|
|2 |Igor Julião Gonçalves|
|3 |Mário Marques Silva  |
|4 |David Silva          |

How could I catch all the people who have Silva in the name?

$string = "Silva";
$sql = "SELECT * FROM usuarios WHERE nome IN('{$string}');
  • 2

    I couldn’t use the operator LIKE?

  • Could inform which is the database, because there is an artificial that can significantly improve the query time and each BDMS implements it in a way.

  • the name of the bank is cde3.

  • It is difficult to present a really efficient solution without knowing the name of the database engine, I googled cde3 database I found nothing. The solutions presented have time complexity O(n x m) where n is the number of records and m is the total of characters to be searched as a solution using natively Inverted index has time complexity O(log n).

  • Ahhh, I thought you were asking the name of my database.

2 answers

4

In addition, use the option Upper/Lower for best use.

SELECT * FROM usuarios WHERE upper(nome) LIKE upper('%Silva%'). 

So you guarantee that the result will be 'Silva', no matter how you write it (SiLvA, sILvA, etc.).

3


To return all the people who have Silva anywhere in the text, use the operator LIKE.

SELECT * FROM usuarios WHERE nome LIKE '%Silva%'

Stay tuned for the performance cost of this operation.

  • I agree the LIKE operator can consume a lot in a query depending on the size of the entity to which the search is made.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.