從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中文網其他相關文章!