Problems filtering field with LIKE in Mysql

Asked

Viewed 625 times

-1

I have a table that has more than 1 million data that I want to filter through an acronym that can be anywhere in the String field. It has BTREE index in Mysql. I’m doing it this way:

select instituicao, count(instituicao)
from base_wos
WHERE instituicao LIKE '%{$Sigla}%' GROUP BY instituicao limit 1250000;

When executing this query I get no return, and the same has non-zero amount in the database.

I am using the Mysql Workbench tool.

  • This query is inside a PHP?

  • I am using the Mysql Workbench itself.

  • In fact Group By institution ? and {$acronym} Workbench will not understand only in PHP this ...

  • I forgot to put here more is with the group yes.

  • It was because of this strange excerpt that I asked if I was using PHP: '%{$Sigla}%'.

1 answer

3


I managed to solve the problem that way:

select instituicao, count(*)
from base_wos
WHERE instituicao LIKE '%Sigla%' GROUP BY instituicao limit 1250000;

The problem was the syntax of PHP being used in SQL by mistake. Like uses only % as a joker, and the substring has to be written literally.

Browser other questions tagged

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