1.簡單查詢 mysql> select * from students where sname like 'o%'; + + + + + | id | sname | sex | tid | + + + + + | 0000000001 | orna | 男 | NULL | + + + + + ...
1.簡單查詢
mysql> select * from students; +------------+----------+------+------+ | id | sname | sex | tid | +------------+----------+------+------+ | 0000000001 | orna | 男 | NULL | | 0000000002 | luscy | 女 | NULL | | 0000000003 | wangwu | 男 | NULL | | 0000000020 | zhangsan | 男 | NULL | +------------+----------+------+------+ 4 rows in set (0.00 sec) mysql> select id,ifnull(sname,'無') name from students; +------------+----------+ | id | name | +------------+----------+ | 0000000001 | orna | | 0000000002 | luscy | | 0000000003 | wangwu | | 0000000020 | zhangsan | +------------+----------+ 4 rows in set (0.00 sec)
mysql> select * from students where sname like 'o%';
+------------+-------+------+------+
| id | sname | sex | tid |
+------------+-------+------+------+
| 0000000001 | orna | 男 | NULL |
+------------+-------+------+------+
1 row in set (0.00 sec)
2.排序
mysql> select * from students order by sname desc; +------------+----------+------+------+ | id | sname | sex | tid | +------------+----------+------+------+ | 0000000020 | zhangsan | 男 | NULL | | 0000000003 | wangwu | 男 | NULL | | 0000000001 | orna | 男 | NULL | | 0000000002 | luscy | 女 | NULL | +------------+----------+------+------+ 4 rows in set (0.00 sec) mysql> select * from students order by sname desc limit 1; +------------+----------+------+------+ | id | sname | sex | tid | +------------+----------+------+------+ | 0000000020 | zhangsan | 男 | NULL | +------------+----------+------+------+ 1 row in set (0.00 sec)