Select with detailed like

Asked

Viewed 195 times

1

How to perform a select because it may not be an exact comparison in the database. I know there is a LIKE, but I’ve tried and not surtiu the desired effect.

The problem is this, I have to search in the bank for a name that may be missing a letter at the end or at the beginning, for example, in the bank can be like this JOSIVAN SOUSA but the search entry may be:

  • JOSIVAN SOUS
  • JOSIVAN DE SOUSA
  • OSIVAN SOUSA

And so on and so on.

3 answers

2

It’s no secret.

Select * from suatabela
where seucampo like '%OSIVAN SOUSA%'
  • This select does not give me the desired result

  • The term search may be JOSIVAN DE SOUSA and the one in the bank may be JOSIVAN SOUSA

  • 1

    That’s gambiara...

  • Following your description of the problem, where a character may be missing at the end or at the beginning of the full name. The only viable solution is @Marconciliosouza. For if not, what would be the search pattern? S

2

select * 
  from suatabela
 where seucampo like '%_OSIVAN SOUSA_%'
  • Doesn’t work for my problem

  • _ says it needs to have some character in that position, does not answer the question.

2

MySQL has a set of functions that you can use to work with String, for example SUBSTRING.

SELECT * FROM users WHERE 1=1 AND ( SUBSTRING(name,2,16) = "OSIVAN DE SOUSA" OR SUBSTRING(name,1,15) = "JOSIVAN DE SOUS" )

Browser other questions tagged

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