LIKE, IN and BETWEEN
Matching text patterns with LIKE
= only matches text exactly. To match a pattern, use LIKE with two wildcards:
%stands for any run of characters (including none)_stands for exactly one character
'S%' means "starts with S". '%a%' means "contains an a". '_o%' means "an o as the second letter".
LIKE를 이용한 텍스트 패턴 매칭
=는 텍스트를 정확히 일치하도록만 매칭합니다. 패턴을 매칭하려면 두 개의 와일드카드가 포함된 LIKE를 사용하세요:
%는 임의의 문자列(공백 포함)을 나타냅니다 (빈 문자열도 가능)_은 정확히 하나의 문자를 의미합니다
SELECT name FROM student WHERE name LIKE 'S%';
'S%'은 "S로 시작"을 의미합니다. '%a%'은 "a가 포함되어 있음"을 의미합니다. '_o%'은 "두 번째 문자가 o"를 의미합니다.
Lists and ranges: IN and BETWEEN
Two more handy tests:
IN (…)matches any value in a list:WHERE form IN ('11A', '11C')BETWEEN low AND highmatches a range, including both ends:
Both are shorter than writing several ORs.
목록 및 범위: IN 및 BETWEEN
더有用的的两个测试:
IN (…)은 목록의 어떤 값에도 매칭합니다:WHERE form IN ('11A', '11C')BETWEEN low AND high은 범위를 매칭하며, 양쪽 끝을 포함합니다:
SELECT name, score FROM student WHERE score BETWEEN 70 AND 90;
둘 다 여러 OR을 쓰는 것보다 짧습니다.
Common mistakes
- In
LIKE,%matches any text:'A%'means "starts with A". BETWEEN a AND bincludes both ends.
흔한 실수
LIKE에서%는 모든 텍스트와 매칭하며:'A%'은 "A로 시작"을 의미합니다.BETWEEN a AND b은 양쪽 끝을 포함합니다.
Pattern & range filters
LIKE / IN / BETWEEN are all WHERE — they keep matching rows.
Show the name of every student whose name contains the letter a. Use LIKE with %.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.
Show the name and score of students whose score is between 70 and 90 (inclusive). Use BETWEEN.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.