这里的"*"是一个通配符,它表示任意匹配,如果你学过基本的正则表达式,这应该比较好理解,所以"*"放在列的位置,表示的是要查询所有列的数据;我们是查询network3这张表中的全部列的数据。
(2)查询表中特定列的数据
操作如下:
1 2 3 4 5 6 7 8 9 10 11
mysql> select id,name from network3; +------------+--------+ | id | name | +------------+--------+ | 3114006440 | Xuan | | 3114006441 | xpleaf | | 3114006442 | Jim | | 3114006443 | Pei | | 3214006336 | Ting | +------------+--------+ 5 rows in set (0.00 sec)
这里我们只查询了表network3中两列的内容,如果还想查询其它列的,像上面的操作那样,在列名称的位置用逗号","隔开就可以了。
(3)按特定条件查询表中的数据
有时我们可能只想要得到某个人或者相同性别的数据,这时候我们就需要指定条件来进行查询了,基本的命令语法如下:
select 列名称 from 数据库表名 where 查询条件;
看我下面的操作:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
mysql> select * from network3 where name='xpleaf'; +------------+--------+------+-----+----------+ | id | name | sex | age | address | +------------+--------+------+-----+----------+ | 3114006441 | xpleaf | male | 35 | QingYuan | +------------+--------+------+-----+----------+ 1 row in set (0.02 sec) mysql> select * from network3 where sex='female'; +------------+------+--------+-----+----------+ | id | name | sex | age | address | +------------+------+--------+-----+----------+ | 3214006336 | Ting | female | 30 | ChaoShan | +------------+------+--------+-----+----------+ 1 row in set (0.00 sec) mysql> select * from network3 where sex='male' and address='QingYuan'; +------------+--------+------+-----+----------+ | id | name | sex | age | address | +------------+--------+------+-----+----------+ | 3114006441 | xpleaf | male | 35 | QingYuan | +------------+--------+------+-----+----------+ 1 row in set (0.00 sec) mysql> select * from network3 where age > 40; +------------+------+------+-----+---------+ | id | name | sex | age | address | +------------+------+------+-----+---------+ | 3114006443 | Pei | male | 41 | PuNing | +------------+------+------+-----+---------+ 1 row in set (0.00 sec) mysql> select * from network3 where age < 40 and age >= 31; +------------+--------+------+-----+----------+ | id | name | sex | age | address | +------------+--------+------+-----+----------+ | 3114006440 | Xuan | male | 36 | ShanWei | | 3114006441 | xpleaf | male | 35 | QingYuan | | 3114006442 | Jim | male | 38 | JiangMen | +------------+--------+------+-----+----------+ 3 rows in set (0.01 sec) mysql> select * from network3 where name like "%leaf"; +------------+--------+------+-----+----------+ | id | name | sex | age | address | +------------+--------+------+-----+----------+ | 3114006441 | xpleaf | male | 35 | QingYuan | +------------+--------+------+-----+----------+ 1 row in set (0.00 sec)