0%

3.4.3 select子句中的属性说明

3.4.3 select子句中的属性说明

选中from子句结果关系中一个关系的所有属性

星号”*“可以用在select子句中表示”所有的属性”,因而,如下查询的select子句中使用instructor.*

1
2
3
select instructor.*
from instructor,teaches
where instructor.ID=teaches.ID;

表示instructor中的所有属性都被选中。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
mysql> select instructor.*
from instructor,teaches
where instructor.ID=teaches.ID;
+-------+------------+------------+--------+
| ID | name | dept_name | salary |
+-------+------------+------------+--------+
| 76766 | Crick | Biology | 72000 |
| 76766 | Crick | Biology | 72000 |
| 10101 | Srinivasan | Comp. Sci. | 65000 |
| 45565 | Katz | Comp. Sci. | 75000 |
| 83821 | Brandt | Comp. Sci. | 92000 |
| 83821 | Brandt | Comp. Sci. | 92000 |
| 10101 | Srinivasan | Comp. Sci. | 65000 |
| 45565 | Katz | Comp. Sci. | 75000 |
| 83821 | Brandt | Comp. Sci. | 92000 |
| 10101 | Srinivasan | Comp. Sci. | 65000 |
| 98345 | Kim | Elec. Eng. | 80000 |
| 12121 | Wu | Finance | 90000 |
| 32343 | El Said | History | 60000 |
| 15151 | Mozart | Music | 40000 |
| 22222 | Einstein | Physics | 95000 |
+-------+------------+------------+--------+
15 rows in set

选中from子句结果关系的所有属性

形如select * from ...select子句表示from子句结果关系的所有属性都被选中,例如:

1
2
3
select *
from instructor,teaches
where instructor.ID=teaches.ID;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
mysql> select *
from instructor,teaches
where instructor.ID=teaches.ID;
+-------+------------+------------+--------+-------+-----------+--------+----------+------+
| ID | name | dept_name | salary | ID | course_id | sec_id | semester | year |
+-------+------------+------------+--------+-------+-----------+--------+----------+------+
| 76766 | Crick | Biology | 72000 | 76766 | BIO-101 | 1 | Summer | 2009 |
| 76766 | Crick | Biology | 72000 | 76766 | BIO-301 | 1 | Summer | 2010 |
| 10101 | Srinivasan | Comp. Sci. | 65000 | 10101 | CS-101 | 1 | Fall | 2009 |
| 45565 | Katz | Comp. Sci. | 75000 | 45565 | CS-101 | 1 | Spring | 2010 |
| 83821 | Brandt | Comp. Sci. | 92000 | 83821 | CS-190 | 1 | Spring | 2009 |
| 83821 | Brandt | Comp. Sci. | 92000 | 83821 | CS-190 | 2 | Spring | 2009 |
| 10101 | Srinivasan | Comp. Sci. | 65000 | 10101 | CS-315 | 1 | Spring | 2010 |
| 45565 | Katz | Comp. Sci. | 75000 | 45565 | CS-319 | 1 | Spring | 2010 |
| 83821 | Brandt | Comp. Sci. | 92000 | 83821 | CS-319 | 2 | Spring | 2010 |
| 10101 | Srinivasan | Comp. Sci. | 65000 | 10101 | CS-347 | 1 | Fall | 2009 |
| 98345 | Kim | Elec. Eng. | 80000 | 98345 | EE-181 | 1 | Spring | 2009 |
| 12121 | Wu | Finance | 90000 | 12121 | FIN-201 | 1 | Spring | 2010 |
| 32343 | El Said | History | 60000 | 32343 | HIS-351 | 1 | Spring | 2010 |
| 15151 | Mozart | Music | 40000 | 15151 | MU-199 | 1 | Spring | 2010 |
| 22222 | Einstein | Physics | 95000 | 22222 | PHY-101 | 1 | Fall | 2009 |
+-------+------------+------------+--------+-------+-----------+--------+----------+------+
15 rows in set

原文链接: 3.4.3 select子句中的属性说明