select col1, col2, ...
from tablename
where condition AND condition2, condition3, .. ;
select col1, col2, ..
from tablename
where conditon1, condition2, condition3, ... ;
select * from celeb where (age<29 and sex='F') OR (age<30 and se
x='M') order by age, sex;
select * from celeb where (agency='YG엔터테이먼트' or agency='나무엑터스')and age<30;
select * from celeb where (sex='M' and agency='YG엔터테이먼트') or age <30 order by age, agency;
select * from celeb where ((id%2)=1 and sex='M') or ((id%2=0) and agency='YG엔터테이먼트') order by age;
정의
조건을 만족하지 않는 경우 TRUE
select col1, col2,
from tablename
where NOT condition;
예제1
* 소속사가 YG엔터테이먼트이면서 남자가 아니거나, 직업이 가수이면서 소속사가 YG 엔터테이먼트가 아닌 데이터 검색
select * from celeb where (AGENCY='YG엔터테이먼트' and not SEX='M') or (JOB_TITLE='가수' and not AGENCY='YG엔터테이먼트');
예제2
* 생일이 1990년 이후이면서 여자가 아니거나, 생일이 1979년 이전이면서 소속사가 안테나가 아닌 데이터
select * from celeb
where (brithday >19891231 and not sex='F') or (birthday<19800101 and not agency='안테나');
예제3
* celeb 테이블에서 소속사가 YG엔터테이먼트가 아니고 나이가 40세 이하인 데이터를 이름순으로 정렬하여 조회해보자.
select * from celeb
where (not agency='YG엔터테이먼트' and age <=40) order by name;
예제 4
* celeb 테이블에서 직업이 가수가 아니면서 성별이 여자이거나, 나이가 40보다 작지 않으면서 아이디가 홀수인 데이터를 조회해보자.
select * from celeb
where (not job_title='가수' and sex='F') or (not age<40 and id%2=1);
select col1, col2
from tablename
where col BETWEEN val1 AND val2;
select * from celeb
where (NOT birthday Between 19800101 and 19951231 and sex='F') or (agency='YG엔터테이먼트 and NOT age BETWEEN 20 and 45);
select * from celeb
where (id between 1 and 5 AND sex='F') or (id%2=1 AND sex='M' AND age BETWEEN 20 and 30);
select col1, col2
from tablename
where col IN (val1, val2, ...);
select * from celeb where age IN (28, 48);
select * from celeb
where (Not agency IN ('나무엑터스',안테나','울림엔터테이먼트') AND sex='F' OR age >=45;
select * from celeb
where NOT agency IN ('안테나', 'YG엔터테이먼트') AND sex='F'
select * from celeb
where (name IN ('아이유','송강','강동원','차승원)) AND (NOT agency='YG엔터테이먼트' OR age BETWEEN 40 and 50);
select col1, col2,
from tablename
where col LIKE pattern;
select * from celeb
where agency LIKE 'YG엔터테이먼트';
select * from celeb where agency LIKE'YG%';
select * from celeb
where job_title LIKE '%가수%';
select * from celeb
where agency LIKE '_G%';
select * from celeb where job_title LIKE '가__%';
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 '%탤런트%');
select * form celeb
where job_title LIKE %가수% AND name LIKE '이%'
select * from celeb
where name IN ('아이유','이미주','유재석','송강') AND agency='나무%';