要共用兩個表格的數據,可以使用MySQL中的JOIN操作來實現。
假設有以下兩個表格:
表格1:employees
+----+-------+--------+
| id | name | salary |
+----+-------+--------+
| 1 | John | 5000 |
| 2 | Mary | 6000 |
| 3 | Peter | 7000 |
+----+-------+--------+
表格2:departments
+----+------------+
| id | department |
+----+------------+
| 1 | IT |
| 2 | HR |
| 3 | Finance |
+----+------------+
要共用這兩個表格的數據,可以使用下面的SQL查詢語句:
SELECT * FROM employees
JOIN departments ON employees.id = departments.id;
執行上述查詢語句后,將會返回以下結果:
+----+-------+--------+----+------------+
| id | name | salary | id | department |
+----+-------+--------+----+------------+
| 1 | John | 5000 | 1 | IT |
| 2 | Mary | 6000 | 2 | HR |
| 3 | Peter | 7000 | 3 | Finance |
+----+-------+--------+----+------------+
這樣就可以將兩個表格的數據共用起來,通過JOIN操作將它們關聯在一起。