먼저 테이블을 생성하겠습니다 -
mysql> create table DemoTable -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(100) -> ); Query OK, 0 rows affected (0.67 sec)
삽입 명령을 사용하여 테이블에 일부 레코드 삽입 -
mysql> insert into DemoTable(Name) values('John'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(Name) values('David'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable(Name) values('Carol'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(Name) values('Bob'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(Name) values('Mike'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(Name) values('Chris'); Query OK, 1 row affected (0.22 sec)
select 문을 사용하여 테이블의 모든 레코드 표시 -
mysql> select *from DemoTable;
출력
+----+-------+ | Id | Name | +----+-------+ | 1 | John | | 2 | David | | 3 | Carol | | 4 | Bob | | 5 | Mike | | 6 | Chris | +----+-------+ 6 rows in set (0.00 sec)
다음은 특정 id로 시작하는 레코드를 선택하는 쿼리입니다.
mysql> select *from DemoTable where Id>=2 order by Id DESC;
출력
+----+-------+ | Id | Name | +----+-------+ | 6 | Chris | | 5 | Mike | | 4 | Bob | | 3 | Carol | | 2 | David | +----+-------+ 5 rows in set (0.00 sec)