阅读量:0
要共用两个表格的数据,可以使用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操作将它们关联在一起。