#去重复查询DISTINCT
mysql> select * from student;
+------+------+------+
| uid | name | age |
+------+------+------+
| 3 | hong | 30 |
| 2 | aaa | 20 |
| 1 | bbb | 26 |
| 4 | ccc | 20 |
| 4 | ccc | 30 |
+------+------+------+
5 rows in set (0.00 sec)
mysql> select distinct name from student;
+------+
| name |
+------+
| hong |
| aaa |
| bbb |
| ccc |
+------+
4 rows in set (0.00 sec)
#使用AND和OR进行多条件查询
mysql> select * from student where uid=5 and age<30;
Empty set (0.00 sec)
mysql> select * from student where age>30;
+------+------+------+
| uid | name | age |
+------+------+------+
| 5 | eee | 31 |
+------+------+------+
1 row in set (0.00 sec)
mysql> select * from student where uid<5 or age>30;
+------+------+------+
| uid | name | age |
+------+------+------+
| 2 | aaa | 20 |
| 1 | bbb | 26 |
| 4 | ccc | 20 |
| 3 | ccc | 30 |
| 5 | eee | 31 |
+------+------+------+
5 rows in set (0.00 sec)
#要加括号
mysql> select * from student where name='aaa' and (age=20 or age=30);
+------+------+------+
| uid | name | age |
+------+------+------+
| 2 | aaa | 20 |
+------+------+------+
1 row in set (0.00 sec)