SQL自学,mysql从入门到精通 --- 第 3 天,select 语句的使用

SQL自学第三天,SELECT语句的使用

-- 查询全表的内容
root@mysqldb 15:32:  [sql_self_learning_skills]> select * from personnel_information;
+--------------+------+----------+
| name         | age  | job      |
+--------------+------+----------+
| Bill Jackson | 25   | engineer |
| 张三         | 35   | farmer   |
| 王五         | 40   | 教师     |
+--------------+------+----------+
3 rows in set (0.00 sec)

-- WHERE 的使用

root@mysqldb 15:35:  [sql_self_learning_skills]> SELECT name, age
    -> FROM personnel_information
    -> WHERE name="Bill Jackson";
+--------------+------+
| name         | age  |
+--------------+------+
| Bill Jackson | 25   |
+--------------+------+
1 row in set (0.00 sec)

-- DISTINCT的使用,过滤掉重复数据

-- 插入一条语句
root@mysqldb 15:41:  [sql_self_learning_skills]> INSERT INTO 
    -> personnel_information VALUES
    -> ("Jack","25","teacher");
Query OK, 1 row affected (0.00 sec)

root@mysqldb 16:07:  [sql_self_learning_skills]> SELECT age FROM personnel_information;
+------+
| age  |
+------+
| 25   |
| 25   |
| 35   |
| 40   |
+------+
4 rows in set (0.00 sec)

root@mysqldb 16:08:  [sql_self_learning_skills]> SELECT DISTINCT age FROM personnel_information;
+------+
| age  |
+------+
| 25   |
| 35   |
| 40   |
+------+
3 rows in set (0.00 sec)

你可能感兴趣的:(SQL,sql,数据库)