SELECT * FROM 테이블; ( * : 모든필드 )
SELECT 필드1, 필드2 FROM 테이블;
SELECT 테이블.필드1, 테이블.필드2 FROM 테이블;
SELECT 테이블1.필드1, 테이블1.필드2, 테이블2.필드1 FROM 테이블1, 테이블2;
(실제로는 JOIN 과 함께 사용)
SELECT * FROM BOOK;
SELECT BOOK_ID, BOOK_NAME FROM BOOK;
SELECT 필드 AS 새이름 FROM 테이블;
SECECT BOOK_IOC AS 책위치 FROM BOOK;
ASC: 오름차순 정렬 (생략 가능) (ASCENDING)
DESC: 내림차순 정렬 (DESCENDING)
SELECT * FROM STUDENT ORDER BY NO;
SELECT * FROM STUDENT ORDER BY NO DESC
SELECT * FROM STUDENT ORDER BY NAME, NO DESC
GROUP BY 그룹필드;
GROUP BY 그룹필드 HAVING 조건식;
SELECT SUM(필드) FROM 테이블 GROUP BY 그룹필드;
SELECT SUM(POINT) FROM BUY GROUP BY MEMBERSHIP;
SELECT SUM(POINT) FROM BUY GROUP BY MEMBERSHIP HAVING MEMBERSHIP='GOLD';
SELECT * FROM STUDENT WHERE DEPT = '경영';
SELECT * FROM STUDENT WHERE DEPT <> '경영';
SELECT * FROM STUDENT WHERE DEPT != '경영';
SELECT * FROM STUDENT WHERE HOME_PHONE = NULL;
SELECT * FROM STUDENT WHERE HOME_PHONE IS NULL;
SELECT * FROM STUDENT WHERE HOME_PHONE IS NOT NULL;
와일드카드 문자 | 설명 | 예 |
---|---|---|
% | 0개 이상의 문자를 가진 문자열 | WHERE title LIKE '%computer%' 책 제목에 'computer' 단어가 있는 모든 책 제목을 찾음 |
_(밑줄) | 단일 문자 | WHERE au_fname LIKE '_ean'ean으로 끝나는 모든 4문자 이름을 찾음 (Dean, Sean 등) |
SELECT * FROM STUDENT WHERE ADDR LIKE '서울%';
서울시 => 서울_
서울특별시 => 서울___
=> 서울%
EMAIL 이 GMAIL.COM 으로 끝나는 학생 출력
SELECT * FROM STUDENT WHERE EMAIL LIKE '%GMAIL.COM';
SELECT * FROM STUDENT WHERE ID LIKE '%A%';
SELECT * FROM STUDENT WHERE NO LIKE'__A%';
SELECT * FROM STUDENT WHERE SCORE BETWEEN 80 AND 89;
SELECT * FROM STUDENT WHERE NO >= 3 AND SCORE >= 90;`
SELECT * FROM STUDENT WHERE ADDR = '서울' OR ADDR = '인천';
SELECT * FROM STUDENT WHERE ADDR IN('서울', '인천');