728x90
반응형
mysql 에도 LIKE IN 이 있는 줄 알고 조회 했더니 에러가 났다.
select * from news where title like in ('%test2%', '%test3%')
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'in ('%test2%', '%test3%')' at line 1
조사해 보니 mysql 에는 LIKE IN 이 없는 것 같다.
아래 참고사이트에 의하면 REGEXP 를 사용하면 된단다. 오홋!
사용할땐 LIKE IN 대신 REGEXP 를 넣고 문자열은 '검색하고싶은단어|검색하고싶은단어2' 구분자(|)를 넣어주면 된다.
select * from news where title REGEXP 'test2|test3'

그리고 보통 IN 을 사용해서 아래와 같이 쓰는데
select * from news where title in (select name from products)
여기에 LIKE IN 처럼 사용하고 싶다면 group_concat 을 이용하면 된다.
select * from news where title REGEXP (select group_concat(name separator'|') from products)
참고사이트
728x90
반응형