让我们首先创建一个表-
mysql> create table DemoTable ( UserId int, UserName varchar(10), UserAge int );
使用插入命令在表中插入记录-
mysql> insert into DemoTable values(101,'Chris',23); mysql> insert into DemoTable values(102,'Robert',33); mysql> insert into DemoTable values(103,'David',25); mysql> insert into DemoTable values(104,'Carol',35); mysql> insert into DemoTable values(105,'Bob',29);
使用选择命令显示表中的记录-
mysql> select *from DemoTable;
这将产生以下输出-
+--------+----------+---------+ | UserId | UserName | UserAge | +--------+----------+---------+ | 101 | Chris | 23 | | 102 | Robert | 33 | | 103 | David | 25 | | 104 | Carol | 35 | | 105 | Bob | 29 | +--------+----------+---------+ 5 rows in set (0.00 sec)
以下是查询以选择其中value = 1或value = 2的列,例如在我们的表中具有不同年龄的UserAge-
mysql> select *from DemoTable where UserAge=25 or UserAge=35 or UserAge=33 or UserAge=29;
这将产生以下输出-
+--------+----------+---------+ | UserId | UserName | UserAge | +--------+----------+---------+ | 102 | Robert | 33 | | 103 | David | 25 | | 104 | Carol | 35 | | 105 | Bob | 29 | +--------+----------+---------+ 4 rows in set (0.00 sec)