MySQL查询以选择从特定ID开始的记录
让我们首先创建一个表-
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)
热门推荐
1 带狗狗训练
4 听力训练狗狗
6 怎训练狗狗
7 腹肌训练狗狗
8 网球训练狗狗
9 记叙文训练狗狗
10 狗狗太凶怎么训练
11 核心力量训练狗狗
12 狗狗乱叫怎么训练
13 发音训练狗狗
14 怎么训练狗狗叼东西给主人
15 荆州训练狗狗
16 篮球训练狗狗
17 做训练狗狗
18 训练狗狗坐姿