본문 바로가기

데이터베이스

DBMS - (13) null value

DBMS - (13) null value

<그림 1: relation example>

NULL value? undefined or unknown

Example
College(cName, state, enrollment)
Student(sID, sName, GPA, size of HS)
Apply(sIDcNamemajor, decision)

GPA, decision은 null이 허용된다.

insert into Student values(432, 'Kevin', null, 1500);
insert into Student values(321, 'Lori', null, 2500);

Q1)
select sID, sName, GPA
from Student
where GPA > 3.5 or GPA <= 3.5

쿼리 결과 반환값에 Kevin, Lori가 없다. 값이 null인 경우 위 condition에 필터링되지 않음.

Q2)
select sID, sName, GPA
from Student
where GPA > 3.5 or GPA <= 3.5 or GPA is null;

GPA is null condition에 매칭되어 Kevin, Lori가 쿼리 결과에 포함됨

Q3)
select count(*)
from Student
where GPA is not null;

GPA is not null condition을 통해 GPA가 null인 튜플을 필터링 할 수 있음

Q4)
select count(distinct GPA)
from Student;

Q4 쿼리 결과는 중복과 null을 제거한 숫자를 나타냄

Q5)
select distinct GPA
from Student;

Q5 쿼리 결과는 중복을 제거하지만 null을 포함

Reference
https://www.youtube.com/watch?v=qdR2z_Ws56k&list=PL6hGtHedy2Z4EkgY76QOcueU8lAC4o6c3&index=16