MariaDB [test]> SELECT * FROM person;+----+-------+------+--------+---------+
| id | name | age | gender | dept_no |
+----+-------+------+--------+---------+
| 1 | kai | 27 | 1 | 1 |
| 2 | gerda | 25 | 2 | 2 |
| 3 | ragi | 33 | 1 | 1 |
+----+-------+------+--------+---------+
3 rows in set (0.00 sec)
MariaDB [test]> SELECT * FROM department;+----+----------------+
| no | name |
+----+----------------+
| 1 | sales |
| 2 | human resource |
+----+----------------+
2 rows in set (0.00 sec)
person テーブルは p、department は d という別名を付けています。一度別名を付けると、後続の WHERE 句では p、d と短い別名を使うことで簡潔な記述になっています。
MariaDB [test]> SELECT p.name, d.name from person AS p, department AS d WHERE p.dept_no = d.no;+-------+----------------+
| name | name |
+-------+----------------+
| kai | sales |
| gerda | human resource |
| ragi | sales |
+-------+----------------+
3 rows in set (0.00 sec)
0 件のコメント:
コメントを投稿