Mysql query with LIKE

Asked

Viewed 803 times

0

I made the query below to return all records containing the word 'Juscelino' in the user table, the word 'Juscelino' repeats 3 times, the query searches in 3 different fields, which is not required to contain in all fields the word to return the result.

Running the query in phpMyAdmin the result is zero, no errors, should return the 3 records of the table with the related data, but returns nothing.

SELECT 
    `user_email`,
    `user_username`,
    `user_nome`,
    `user_sobrenome`,
    `user_token` 
FROM 
    `usuario` 
WHERE 
    `user_nome` 
LIKE '
    %Juscelino%'
OR 
    `user_sobrenome` 
LIKE 
    '%Juscelino%'
OR 
    `user_username` 
LIKE 
    '%Juscelino%'
ORDER BY 
    `user_nome` ASC,
    `user_sobrenome` ASC

The table has its collation set to 'utf8_general_ci', and is a Myisam table.

  • 1

    As Ronaldo said, there is a line break inside the LIKE quotes

  • @Bacco, what is the reason for being outside the scope if it is a genuine and real difficulty?

  • The message is on the yellow board. Since the solution has already been found and it is only a typo, then it is not a case that justifies the posting stay as future reference for other visitors (which, after all, is the philosophy of the site).

2 answers

2


WHERE 
    user_nome
LIKE ' --    <---- o erro está aqui
    %Juscelino%'
  • I changed and it worked, our fault, the return did not give error anyway. abs

-1

Try using ilike to disregard uppercase letters:

 SELECT 
`user_email`,
`user_username`,
`user_nome`,
`user_sobrenome`,
`user_token` 
FROM 
  `usuario` 
WHERE 
  `user_nome` 
ILIKE '
   %Juscelino%'
OR 
  `user_sobrenome` 
ILIKE 
'%Juscelino%'
OR 
`user_username` 
ILIKE 
'%Juscelino%'
ORDER BY 
`user_nome` ASC,
`user_sobrenome` ASC

Browser other questions tagged

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