2.SELECT 데이터 불러오기(형식, alias, distinct, order by, (where, (and, between 연산자), (or, in 연산자), not, like 연산자)
테이블 목록 불러오기 : SELECT * FROM TAB;
테이블 구조 불러오기 : DESC 테이블명;
-기본 형식
SELECT 컬럼 FROM 테이블명;
-Alias 컬럼 별칭 붙이기 (3가지 방법 다 가능)
SELECT 컬럼 AS '별칭' FROM 테이블명;
SELECT 컬럼 '별칭' FROM 테이블명;
SELECT 컬럼 별칭 FROM 테이블명;
-distinct 중복된 데이터 제거
SELECT job_id from employees;
SELECT DISTINCT job_id from employees; 비교
-order by 컬럼명 정렬 묶음 검색
SELECT 컬럼 from 테이블 ORDER BY 컬럼명|인덱스;
기본 : 오름차순
내림차순 ORDER BY 컬럼명 DESC;
오름차순 ORDER BY 컬럼명 ASC;
-조건에 맞는 일부 데이터 where
select 컬럼 from 테이블 where 조건절;
-And 연산자/ Between and
예시)
select employee_id, last_name, salary from employees where salary>=5000 and salary<=10000;
select employee_id, last_name, salary from employees where salary between 5000 and 10000;
-Or 연산자/ in 연산자
예시)
select employee_id, last_name, job_id from employees where job_id='FI_MGR' or job_id='FI_ACCOUNT';
select employee_id, last_name, job_id from employees where job_id in ('FI_MGR','FI_ACCOUNT');
-NOT 연산자, ^=, !=, <>
select 컬럼 from 테이블 where NOT 조건절;
-IS NOT NULL 연산자(null이 아닌값들을 뽑고 싶을 때), IS NULL 연산자(null인 값들을 뽑고 싶을 때)
예시)
SELECT employee_id, last_name, commission_pct from employees where commission_pct is not null;
-LIKE 연산자 (검색 시 많이) LIKE '김%' _ 아래 하이픈, % 와 같이 쓰인다
LIKE '김%' ⇒ 김으로 시작하는 모든 문자열
LIKE '%김%' ⇒ 김을 포함하는 모든 문자열
LIKE '%과' ⇒ 과로 끝나는 모든 문자열
LIKE '화_' ⇒ 화로 시작하는 두글자 문자열 ex)화학
LIKE '_등_' ⇒ 등이 가운데 있는 세글자 문자열 ex) 고등어, 꽃등심