select name, age from celeb where age=29 order by age;
select name, age from celeb where age!=29 order by age;
select name, age from celeb where age>29 order by age;
select name, age from celeb where age<29 order by age;
select name, age from celeb where age>=29 order by age;
select name, age from celeb where age<=29 order by age;
select name, age from celeb where age<>29 order by age;
SELECT column1, column2, ...
FROM tablename
WHERE condition1 AND condition2 AND condition3, ...;
SELECT * FROM celeb WHERE age=29 AND sex='F';
SELECT * FROM celeb WHERE sex='M' AND age>40 ORDER BY name DESC;
SELECT column1, column2, ...
FROM tablename
WHERE condition1 OR condition2 OR condition3, ...;
SELECT * FROM celeb WHERE age<25 OR age>30 ORDER BY age;
select * from celeb where (age<29 and sex='F') or (age>30 and sex='M')
order by age, sex;
select * from celeb where (agency='YG엔터테인먼트' or agency='나무엑터스') and age<30;
select * from celeb where (ID%2 = 1 and sex='M') or (ID%2 = 0 and agency='YG엔터테인먼트') order by age;
SELECT column1, column2, ...
FROM tablename
WHERE NOT condition;
select * from celeb where not sex='F';
select * from celeb
where (agency='YG엔터테인먼트' and not sex='M')
or (job_title='가수' and not agency='YG엔터테인먼트');
select * from celeb
where (birthday > 19891231 and not sex='F')
or (birthday < 19800101 and not agency='안테나');
-> 생일이 1990년 이후면서 여자가 아니거나, 생일이 1979년 이전이면서 소속사가 안테나가 아닌 데이터 검색
SELECT column1, column2, ...
FROM tablename
WHERE column1 BETWEEN value1 AND value2;
-> value1, value2 포함! (>=, <=)
select * from celeb
where age BETWEEN 20 AND 40;
select * from celeb
where (NOT birthday BETWEEN 19800101 AND 19951231 and sex='F') or
(agency='YG엔터테인먼트' and NOT age BETWEEN 20 AND 45);
SELECT column1, column2, ...
FROM tablename
WHERE column IN (value1, value2, ...);
-> column값이 value1 or value2 or...
select * from celeb
where age IN (28, 48);
-> 나이가 28, 또는 48인 데이터 검색
select * from celeb
where (NOT agency IN ('나무엑터스', '안테나', '울림엔터테인먼트')) and (
sex='F' or age>=45);
SELECT column1, column2, ...
FROM tablename
WHERE column LIKE pattern;
select * from celeb where agency LIKE 'YG엔터테인먼트';
select * from celeb where agency LIKE 'YG%';
-> 'YG'로 시작하는 소속사 이름을 가진 데이터 검색
select * from celeb where agency LIKE '%엔터테인먼트';
-> '엔터테인먼트'로 끝나는 소속사 이름을 가진 데이터 검색
select * from celeb where job_title LIKE '%가수%';
-> '가수'를 포함한 직업명을 가진 데이터 검색
select * from celeb where agency LIKE '_G%';
-> 소속사 이름의 두 번째 글자가 'G'인 데이터 검색
-> 언더바(_) 개수 : 글자수
select * from celeb where job_title LIKE '가_%';
-> 직업명이 '가'로 시작하고 최소 2글자 이상인 데이터 검색
select * from celeb where job_title LIKE '가____%';
-> 직업명이 '가'로 시작하고 최소 5글자 이상인 데이터 검색
-> '가' + 글자수를 표현하는 언더바 _ 4개
select * from celeb where job_title LIKE '영%모델';
-> 직업명이 '영'으로 시작하고 '모델'로 끝나는 데이터 검색
select * from celeb
where job_title LIKE '%영화배우%' and job_title LIKE '%텔런트%';
-> 영화배우와 텔런트를 병행하는 연예인 검색
select * from celeb
where (job_title LIKE '%,%')
and not (job_title LIKE '%영화배우%' or job_title LIKE '%텔런트%');
-> 직업이 하나 이상(2개이상)인 연예인 중 영화배우 혹은 텔런트가 아닌 연예인 검색
select * from celeb where name like '__';
-> 이름이 두 글자인 데이터 검색
<제로베이스 데이터 취업 스쿨>