먼저 테이블을 생성하겠습니다 -
mysql> create table DemoTable -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(20), -> Age int -> ); Query OK, 0 rows affected (0.63 sec)
삽입 명령을 사용하여 테이블에 일부 레코드 삽입 -
mysql> insert into DemoTable(Name,Age) values('John',21); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(Name,Age) values(Null,20); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(Name,Age) values('David',23); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(Name,Age) values('Carol',null); Query OK, 1 row affected (0.17 sec)
select 문을 사용하여 테이블의 모든 레코드 표시 -
mysql> select *from DemoTable;
출력
+----+-------+------+ | Id | Name | Age | +----+-------+------+ | 1 | John | 21 | | 2 | NULL | 20 | | 3 | David | 23 | | 4 | Carol | NULL | +----+-------+------+ 4 rows in set (0.00 sec)
다음은 OR &AND 조건이 있는 쿼리입니다. -
mysql> select *from DemoTable -> where Name='David' OR (Name is null AND Age=20);
출력
+----+-------+------+ | Id | Name | Age | +----+-------+------+ | 2 | NULL | 20 | | 3 | David | 23 | +----+-------+------+ 2 rows in set (0.00 sec)