php - 交叉引用表并将结果插入另一个表 SQL
问题描述
所以我有 3 个表,如下所示:
表 1 - 猫 - 具有以下结构:
id name plural_name
0 painters painters
1 builders builders
表 2 - 地方 - 具有以下结构
place_id place_name classification
243 painter comp painters
230 builder comp builders
表 3 - rel_place_cat - 具有以下结构
id place_id cat_id
0 243 0
1 230 1
所以基本上我需要运行一个 SQL 命令来查找表 1 中的类别 ID 号和表 2 中的 place_id 并将数据插入表 3
这可以做到吗?
谢谢
解决方案
就像是:
insert into table3(place_id, cat_id)
select place_id, cat_id
from(select place_id, cat_id
from table1
inner join table2 on table1.name = table 2.classification)
应该管用。
推荐阅读
- ios - UIButton 上的 iOS 线性渐变无法正确显示
- php - 如何将 .txt 文件导入到不同表中的 mysql 数据库中
- wso2 - 在 WSO2 IS 中的 JIT 供应期间,如何使用 SAML 响应中给出的声明来填充用户属性?
- gradle - 导入 Gradle 项目会使整个项目落后
- python-3.x - 无法使用 Anaconda Python 导入 sqlite3
- reactjs - 如何使用 React 的 setState() 修复 linting 错误
- python - 如何在 Python 中创建单独的哈希算法实例?
- java - 返回的迭代器可以访问 Java 中的私有数组吗?
- woocommerce - 在类别页面上显示 Woocommerce 面包屑
- neo4j - Cypher 查询以查找具有共享属性的节点,并将其公式化为输入和输出