문제

I need to search a column for a string ,multiple times for variation of the same string, so i did this

SELECT * 
FROM `users` 
WHERE user = 'king'
OR alias = 'king'
OR aliases LIKE '%,king%'
OR aliases LIKE '%king,%'
OR aliases LIKE '%king,%'

the column aliases will contains words separated with comma e.g king,queen,knight etc But because like itself is slow, i am wondering if there is any way i can optimize this query

도움이 되었습니까?

해결책

try this:

SELECT * 
FROM `users` 
WHERE user = 'king'
OR alias = 'king'
OR FIND_IN_SET ('king', aliases)>0;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top