mysql> select * from courses;
+----+---------+---------+-------+
| id | student | class | score |
+----+---------+---------+-------+
| 1 | A | Math | 90 |
| 2 | A | Chinese | 80 |
| 3 | A | English | 70 |
| 4 | A | History | 80 |
| 5 | B | Math | 73 |
| 6 | B | Chinese | 60 |
| 7 | B | English | 70 |
| 8 | B | History | 90 |
| 9 | C | Math | 70 |
| 10 | C | Chinese | 50 |
| 11 | C | English | 20 |
| 12 | C | History | 10 |
| 13 | D | Math | 53 |
| 14 | D | Chinese | 32 |
| 15 | D | English | 99 |
| 16 | D | History | 100 |
+----+---------+---------+-------+
16 rows in set (0.00 sec)mysql> select class, min(score) from courses group by class;
+---------+------------+
| class | min(score) |
+---------+------------+
| Math | 53 |
| Chinese | 32 |
| English | 20 |
| History | 10 |
+---------+------------+
4 rows in set (0.00 sec)mysql> select class from courses group by class;
+---------+
| class |
+---------+
| Chinese |
| English |
| History |
| Math |
+---------+
4 rows in set (0.00 sec)
inner join
mysql> select * from phone;
+----+---------+-------------+
| id | student | phone |
+----+---------+-------------+
| 1 | A | 123123123 |
| 2 | B | 12312312322 |
| 3 | C | 321321 |
+----+---------+-------------+
3 rows in set (0.00 sec)mysql> select * from courses;
+----+---------+---------+-------+
| id | student | class | score |
+----+---------+---------+-------+
| 1 | A | Math | 90 |
| 2 | A | Chinese | 80 |
| 3 | A | English | 70 |
| 4 | A | History | 80 |
| 5 | B | Math | 73 |
| 6 | B | Chinese | 60 |
| 7 | B | English | 70 |
| 8 | B | History | 90 |
| 9 | C | Math | 70 |
| 10 | C | Chinese | 50 |
| 11 | C | English | 20 |
+----+---------+---------+-------+
11 rows in set (0.00 sec)mysql> select a.phone, b.class from phone a inner join courses b on a.student= b.student;
+-------------+---------+
| phone | class |
+-------------+---------+
| 123123123 | Chinese |
| 123123123 | English |
| 123123123 | History |
| 123123123 | Math |
| 12312312322 | Chinese |
| 12312312322 | English |
| 12312312322 | History |
| 12312312322 | Math |
| 321321 | Chinese |
| 321321 | English |
| 321321 | Math |
+-------------+---------+
11 rows in set (0.00 sec)mysql> select distinct a.phone, b.student from phone a inner join courses b on a.student= b.student;
+-------------+---------+
| phone | student |
+-------------+---------+
| 123123123 | A |
| 12312312322 | B |
| 321321 | C |
+-------------+---------+
3 rows in set (0.00 sec)