The IN keyword
Coddy SQL 여정의 기초 섹션에 포함된 레슨 — 72개 중 18번째.
열이 여러 가능한 값 중 하나와 일치하는 행을 찾을 필요가 있을 때, 여러 OR 조건을 사용하여 작성할 수 있습니다. 예를 들어 다음 쿼리는 매우 길어집니다:
SELECT *
FROM table1
WHERE col1 = 'a' OR col1 = 'b' OR col1 = 'c' OR col1 = 'd' OR ...IN 키워드를 사용하면 다음과 같이 간단하게 만들 수 있습니다:
SELECT *
FROM table1
WHERE col1 IN ('a', 'b', 'c', 'd', 'e', 'f')이 더 짧은 버전은 정확히 같은 일을 합니다: col1이 괄호 안에 나열된 값들 중 하나와 같을 때의 행들을 반환합니다.
챌린지
쉬움사용 가능한 테이블 및 컬럼:
<strong>countries</strong>:<strong>location_x</strong>,<strong>location_y</strong>,<strong>country</strong>
다음 국가들의 모든 레코드를 반환하세요:
Oman, Nicaragua, Bhutan, Senegal, Belarus
치트 시트
IN을 사용하여 열이 리스트의 값 중 하나와 일치하는지 확인하세요:
SELECT *
FROM table1
WHERE col1 IN ('a', 'b', 'c', 'd', 'e', 'f')이것은 여러 OR 조건과 동등하지만 훨씬 더 짧습니다.
직접 해보기
이 레슨에는 짧은 퀴즈가 포함되어 있습니다. 레슨을 시작해 문제를 풀고 진행 상황을 기록하세요.
기초의 모든 레슨
4More Keywords
The IN keywordThe BETWEEN keywordThe LIKE keywordThe AS keywordRecap - Cellphone Models2Conditions
Conditions BasicsThe AND keywordThe OR keywordThe NOT keywordMultiple Conditions CombinedParenthesisBooleans5Arithmetic Operations
Mathematical OperatorsMathematical ColumnsThe Modulo OperationThe ROUND() Function3Specific Return Format
Null valuesSort Results Part 1Sort Results Part 2Recap - Cyber Security FirmLimit number of recordsRecap - Vehicle Factory6Intro Challenges
Recap - Parliamentary ElectionRecap - Police Criminal ArrestRecap - Bar Beverage ContainerRecap - Engineer new columns