먼저 테이블을 생성하겠습니다 -
mysql> create table DemoTable635( EmployeId int NOT NULL AUTO_INCREMENT PRIMARY KEY,EmployeeName varchar(100) ); Query OK, 0 rows affected (1.24 sec)
삽입 명령을 사용하여 테이블에 일부 레코드 삽입 -
mysql> insert into DemoTable635(EmployeeName) values('John'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable635(EmployeeName) values('Sam'); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable635(EmployeeName) values(''); Query OK, 1 row affected (0.38 sec) mysql> insert into DemoTable635(EmployeeName) values(null); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable635(EmployeeName) values('David'); Query OK, 1 row affected (0.22 sec)
select 문을 사용하여 테이블의 모든 레코드 표시 -
mysql> select *from DemoTable635;
이것은 다음과 같은 출력을 생성합니다 -
+-----------+--------------+ | EmployeId | EmployeeName | +-----------+--------------+ | 1 | John | | 2 | Sam | | 3 | | | 4 | NULL | | 5 | David | +-----------+--------------+ 5 rows in set (0.00 sec)
다음은 MySQL 열에서 빈 값과 null 값을 표시하지 않는 쿼리입니다. -
mysql> select *from DemoTable635 tbl where tbl.EmployeeName is not null and tbl.EmployeeName <> '';
이것은 다음과 같은 출력을 생성합니다 -
+-----------+--------------+ | EmployeId | EmployeeName | +-----------+--------------+ | 1 | John | | 2 | Sam | | 5 | David | +-----------+--------------+ 3 rows in set (0.02 sec)