Database
-
MySQL - 조인(JOIN)Database/MySQL 2023. 2. 23. 15:30
조인(JOIN) 조인(JOIN)이란? - JOIN은 데이터베이스 내의 여러 테이블에서 가져온 레코드를 조합하여 하나의 테이블이나 결과 집합으로 표현해 주는 연산이다. - 표준 SQL에서는 레코드를 조합하는 방식에 따라 JOIN을 아래와 같이 구분한다. 1. INNER JOIN 2. LEFT JOIN 3. RIGHT JOIN INNER JOIN FROM 테이블명01 INNER JOIN 테이블명02 ON 조건 - INNER JOIN은 ON 절과 함께 사용되며, ON 절의 조건을 만족하는 데이터만을 가져온다. - ON 절에서는 WHERE 절에서 사용할 수 있는 모든 조건을 사용할 수 있다. - 또한, 표준 SQL과는 달리 MySQL에서는 JOIN, INNER JOIN, CROSS JOIN이 모두 같은 의미로 ..
-
MySQL - 서브쿼리(Subquery)Database/MySQL 2023. 2. 23. 14:12
서브쿼리(Subquery) 서브쿼리(Subquery) - 서브쿼리란 다른 쿼리 내부에 포함되어 있는 SELECT 문을 의미한다. - 서브쿼리를 포함하고 있는 쿼리를 외부쿼리라고 부르며, 서브쿼리는 내부쿼리라고도 부른다. - 또한, 서브쿼리는 반드시 괄호로 감싸져 있어야만 한다. SELECT ID, RESERVE_DATE, ROOM_NUM FROM RESERVATION WHERE NAME IN (SELECT NAME FROM CUSTOMER WHERE ADDRESS = '서울') - 위 예제는 주소가 서울인 고객이 예약한 예약 정보만을 선택하는 예제이다. - 위 코드는 우선 CUSTOMER 테이블의 ADDRESS 필드값이 '서울'인 레코드의 NAME 필드를 모두 선택한다. - 그리고나서, RESERVATI..
-
MySQL - 패턴 매칭(LIKE, REGEXP)Database/MySQL 2023. 2. 22. 16:03
패턴 매칭(LIKE, REGEXP) LIKE SELECT * FROM MEMBER WHERE NAME LIKE '홍%'; - LIKE 연산자는 특정 패턴을 포함하는 데이터만을 검색하기 위해 사용된다. - 위 예제는 MEMBER 테이블에서 '홍'으로 시작하는 이름(NAME)을 가진 레코드를 조회하기 위한 예제이다. SELECT * FROM MEMBER WHERE NAME NOT LIKE '홍%'; - 만약, 특정 패턴을 포함하지 않는 데이터를 검색하고 싶을 때는 NOT LIKE 연산자를 사용하면 된다. - 위 예제는 MEMBER 테이블에서 '홍'으로 시작하지 않은 이름(NAME)을 가진 레코드를 조회하기 위한 예제이다. 와일드카드 와일드카드 설명 % 0개 이상의 문자를 대체한다. _ 1개의 문자를 대체한다..
-
MySQL - 데이터 조회(SELECT)Database/MySQL 2023. 2. 22. 13:22
데이터 조회(SELECT) 데이터 조회 - SELECT SELECT 필드명 FROM 테이블명 WHERE 조건 - MySQL에서는 SELECT 문을 사용하여 테이블의 레코드를 선택할 수 있다. - SELECT 키워드 뒤에 조회하고 싶은 필드명을 명시하고, FROM 키워드 뒤에는 레코드를 선택할 테이블명을 명시한다. - WHERE 절을 사용하면, 선택할 레코드의 조건을 좀 더 상세히 설정할 수 있다. 예제 01 SELECT * FROM MEMBER; - 위 예제는 테이블의 모든 필드를 선택하여 조회하는 예제이다. - SELECT 문과 함께 별표(*) 기호를 사용하면, 해당 테이블의 모든 필드를 선택할 수 있다. 예제 02 SELECT * FROM MEMBER WHERE NAME = '홍길동'; - SELEC..
-
MySQL - 데이터 추가(INSERT), 수정(UPDATE), 삭제(DELETE)Database/MySQL 2023. 2. 22. 10:24
데이터 추가(INSERT), 수정(UPDATE), 삭제(DELETE) 데이터 추가 - INSERT 예제 01 INSERT INTO 테이블명(필드명01, 필드명02, 필드명03, ...) VALUES (데이터값01, 데이터값02, 데이터값03, ...); - INSERT INTO 문과 함께 VALUES 절을 사용하여 특정 테이블에 새로운 레코드를 추가할 수 있다. - 테이블 내 필드명과 데이터값을 순서대로 명시하여, 레코드를 삽입할 수 있다. INSERT INTO MEMBER(NAME, AGE) VALUES ('홍길동', '20'); - 위 예제는 MEMBER 테이블의 NAME 필드와 AGE 필드에 '홍길동'과 '20'이라는 값을 삽입하는 예제이다. 예제 02 INSERT INTO 테이블명 VALUES (..
-
Oracle - JOIN 사용 시 ON과 WHERE의 차이Database/Oracle 2023. 2. 21. 14:14
JOIN 사용 시 ON과 WHERE의 차이 쿼리문 01 SELECT * FROM TBLD_01 a LEFT JOIN TBLD_02 b ON (a.aa == b.aa) WHERE b.cc = 7; 위 쿼리문의 경우 TBLD_01과 TBLD_02 테이블에 대해서 OUTER JOIN을 수행한 후 b.cc = 7인 데이터들을 추출한다. 위 쿼리문의 작업 순서는 아래와 같다. 1. TBLD_01과 TBLD_02 테이블의 OUTER JOIN 수행 2. OUTER JOIN 결과들 중 b.cc = 7인 데이터들을 추출 쿼리문 02 SELECT * FROM TBLD_01 a LEFT JOIN TBLD_02 b ON (a.aa = b.aa AND b.cc = 7); 하지만, 위 쿼리문의 경우 TBLD_01과 cc 속성 값..