SQL Query, where the field value does not contain empty spaces

I am currently using the following query:

SELECT *
FROM `wp_usermeta`
WHERE meta_key='avatar'
AND meta_key NOT LIKE '% '
ORDER BY RAND()
LIMIT 4

Thus, I want to try to get only the values โ€‹โ€‹of fields in which there are no empty spaces in the file name. Where is the error in my request? It still selects file names with empty space in the file name.

+3
source share
1 answer

Try

NOT LIKE '% %'

Your current wildcard will only catch trailing spaces.

In addition, you use meta_keytwice. If the column used in your sentence LIKEwill be meta_value(or something else in Wordpress).

This question is probably worth reading if you are concerned about performance - Which is faster - INSTR or LIKE?

+7

Source: https://habr.com/ru/post/1792661/


All Articles