컴

mysql like 검색방법

· 2012-12-02 (일) 12:52:59 · 4943 · 9
너무 궁금해서 아무리 찾아도 저와 비슷한 질문을 한 사람이 없더군요. like 검색시에 대소문자를 구분해서 검색하는 방법이 뭐가 있을까 생각하다가... 예를들어, name 컬럼에 abc 라는 값이 들어있고, select * from table where name like '%Bc%' 이렇게 해도 검색이 되더라 이겁니다. 물론 필드형을 바꾸어 주거나 하는 방법이 있지만.... select * from table where binary(name) like '%Bc%' 이렇게 하면 대소문자를 구분하여 검색이 안되고, select * from table where binary(name) like '%bc%' 이렇게 해야만 검색

첨부파일

mysql_like_검색.txt (50 bytes) 48회 2012-12-02 13:10
|

댓글 9개

http://dev.mysql.com/doc/refman/5.5/en/case-sensitivity.html

To make this search case sensitive, make sure that one of the operands has a case sensitive or binary collation. For example, if you are comparing a column and a string that both have the latin1 character set, you can use the COLLATE operator to cause either operand to have the latin1_general_cs or latin1_bin collation:

col_name COLLATE latin1_general_cs LIKE 'a%'
col_name LIKE 'a%' COLLATE latin1_general_cs
col_name COLLATE latin1_bin LIKE 'a%'
col_name LIKE 'a%' COLLATE latin1_bin
감사합니다
댓글을 작성하시려면 로그인이 필요합니다.

팁게시판

6,077건

디자인과 관련된 유용한 정보를 공유하세요. 질문은 상단의 QA에서 해주시기 바랍니다.

+
제목 글쓴이 날짜 조회
13-05-02 조회 7,812
13-04-29 조회 2,734
13-04-15 조회 2,871
13-04-13 조회 3,746
13-02-27 조회 1,714
13-02-26 조회 3,845
13-02-12 조회 2,925
13-02-01 조회 2.1만
13-01-23 조회 1,157
13-01-09 조회 5,455
13-01-07 조회 2,409
13-01-07 조회 1,075
13-01-04 조회 1.1만
13-01-03 조회 9,209
12-12-31 조회 4,039
12-12-27 조회 1,937
12-12-27 조회 1,500
12-12-27 조회 6,151
12-12-18 조회 1,002
12-12-12 조회 1,578
12-12-12 조회 4,425
12-12-12 조회 5,976
12-12-05 조회 3,077
12-12-01 조회 4,049
12-11-22 조회 1,944