多条件查询(and | or)
mysql> SELECT * FROM pet WHERE species = 'dog' AND sex = 'f';
+‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐+
| name | owner | species | sex | birth | death |
+‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐+
| Buffy | Harold | dog | f | 1989‐05‐13 | NULL |
+‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐+
mysql> SELECT * FROM pet WHERE species = 'snake' OR species = 'bird';
+‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐+
| name | owner | species | sex | birth | death |
+‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐+
| Chirpy | Gwen | bird | f | 1998‐09‐11 | NULL |
| Whistler | Gwen | bird | NULL | 1997‐12‐09 | NULL |
| Slim | Benny | snake | m | 1996‐04‐29 | NULL |
+‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐+
优先执行括号中的逻辑
mysql> SELECT * FROM pet WHERE (species = 'cat' AND sex = 'm')
‐> OR (species = 'dog' AND sex = 'f');
+‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐+
| name | owner | species | sex | birth | death |
+‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐+
| Claws | Gwen | cat | m | 1994‐03‐17 | NULL |
| Buffy | Harold | dog | f | 1989‐05‐13 | NULL |
+‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐+
检索特定的列
mysql> SELECT name, birth FROM pet;
+‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+
| name | birth |
+‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+
| Fluffy | 1993‐02‐04 |
| Claws | 1994‐03‐17 |
| Buffy | 1989‐05‐13 |
| Fang | 1990‐08‐27 |
| Bowser | 1989‐08‐31 |
| Chirpy | 1998‐09‐11 |
| Whistler | 1997‐12‐09 |
| Slim | 1996‐04‐29 |
| Puffball | 1999‐03‐30 |
+‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+
查询不重复的字段要使用关键词DISTINCT
mysql> SELECT DISTINCT owner FROM pet;
+‐‐‐‐‐‐‐‐+
| owner |
+‐‐‐‐‐‐‐‐+
| Benny |
| Diane |
| Gwen |
| Harold |
+‐‐‐‐‐‐‐‐+
可以使用组合条件查询特定的列
mysql> SELECT name, species, birth FROM pet
‐> WHERE species = 'dog' OR species = 'cat';
+‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+
| name | species | birth |
+‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+
| Fluffy | cat | 1993‐02‐04 |
| Claws | cat | 1994‐03‐17 |
| Buffy | dog | 1989‐05‐13 |
| Fang | dog | 1990‐08‐27 |
| Bowser | dog | 1989‐08‐31 |
+‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+