php - 连接表中的 INSERT 语句

标签 php html insert phpmyadmin

我有 3 个表:

tblNames:

|  id  |   firstname   |   lastname   |
+------+---------------+--------------+
|  1   |   John        |   Smith      |

tblJosbs(该表同时接受多个复选框值):

|  id  |   jobs                |
+------+-----------------------+
|  1   |   Nurse               |
+------+-----------------------+
|  2   |   Call Center Agent   |
+------+-----------------------+
|  3   |   Police              |

tblNamesJobs(此表用于JOIN其他 2 个表):

|  id  |   name_id   |   jobs_id   |
+------+-------------+-------------+
|  1   |   1         |   1         |
+------+-------------+-------------+
|  2   |   1         |   2         |
+------+-------------+-------------+
|  3   |   1         |   3         |

一切都很好,但有人可以告诉我当我添加新信息时应该使用的第三个表的 INSERT 语句吗?

最佳答案

例如添加John Smith调用中心代理的记录

insert into tblNamesJobs (name_id,jobs_id )
values (
         select id from tblNames where 
                firstname='John' 
                and lastname='Smith' limit 1
         ,
         select id from tblJosbs where jobs='Call Center Agent' limit 1
        );

关于php - 连接表中的 INSERT 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14079646/

相关文章:

javascript - 有没有办法在搜索栏中用 php 调用模式?

php - 数据提供的最佳实践 - PHPUnit

html - aria-label 和 aria-describedby 可以结合使用吗?

javascript - 折叠内容 - Javascript CSS

php - 了解插入忽略 (MySQL) 是否实际插入到 PHP 中

php - Laravel 5.1 删除关系

php - 我应该如何更改工作表并添加一列来跟踪时间?

javascript - Materialise CSS sidenav 'options' 未定义

c - 链表: Insert function points to itself after second insertion

MySQL:对具有常量值的多行进行条件 INSERT ... SELECT