从 MySQL 中的多个现有表创建新表
要创建一个组合多个现有表中的数据和列的新表,您可以使用JOIN操作。在 MySQL 中,可以通过以下步骤来实现:
SELECT * FROM people AS p JOIN details AS d ON p.id = d.person_id JOIN taxonomy AS t ON d.detail_id = t.id
SELECT p.id, p.last_name, p.first_name, p.email, d.content AS age FROM people AS p JOIN details AS d ON p.id = d.person_id JOIN taxonomy AS t ON d.detail_id = t.id WHERE t.taxonomy = 'age'
CREATE TABLE new_table AS SELECT p.id, p.last_name, p.first_name, p.email, d.content AS age FROM people AS p JOIN details AS d ON p.id = d.person_id JOIN taxonomy AS t ON d.detail_id = t.id WHERE t.taxonomy = 'age'
INSERT INTO new_table (id, last_name, first_name, email, age) SELECT p.id, p.last_name, p.first_name, p.email, d.content AS age FROM people AS p JOIN details AS d ON p.id = d.person_id JOIN taxonomy AS t ON d.detail_id = t.id WHERE t.taxonomy = 'age'
通过使用这些方法,您可以创建新表,组合 MySQL 中多个现有表的数据和列,提供一种方便高效的方式来组织和访问信息。
以上是如何将多个 MySQL 表中的数据合并到一个新表中?的详细内容。更多信息请关注PHP中文网其他相关文章!