Mysql 如果特定列对同一员工不可用则插入

Mysql Insert if the Specific Column is not available for the same Employee

我有一个控制器可以保存一条记录

我的 Table 包含以下字段

这是必须的(必须在 LOOP 中重复)。

我想在 table 中为一个 Employee Id 插入一条记录,并且它不应该再次重复。但同一员工可以有多个批次 ID 和多个课程 ID。

如果我将 Unique 作为员工 Id 再次工作,则将另一条记录插入同一员工。

这个过程应该在循环内重复,我需要从 Table 中获取最后插入的 ID,并且必须在另一个 table 中分配学生人数。如果我在 Mysql 中创建一个过程并且如果我调用过程,这一切都工作正常。但是我的 Linux 服务器没有执行并抛出 MySQL 错误。

这是我的查询

<code>
  
    $insert_staff_assign = "insert into staff_assign 
    (`main_course_id`, `main_batch_id`, `section`, `semester_course_id`, `emp_mas_staff_id`, `emp_category`) 
    VALUES 
    (:main_course_id, :main_batch_id, :section_id, :semester_course_id, :emp_mas_staff_id, :emp_category) 
    ON DUPLICATE KEY UPDATE 
    main_course_id=:main_course_id, main_batch_id=:main_batch_id, section=:section_id, semester_course_id=:semester_course_id, emp_mas_staff_id=:emp_mas_staff_id, emp_category=:emp_category ";

    insert into staff_assign 
    (`main_course_id`, `main_batch_id`, `section`, `semester_course_id`, `emp_mas_staff_id`, `emp_category`) 
    VALUES 
    (:main_course_id, :main_batch_id, :section_id, :semester_course_id, :emp_mas_staff_id, :emp_category) 
    ON DUPLICATE KEY UPDATE 
    main_course_id=:main_course_id, main_batch_id=:main_batch_id, section=:section_id, semester_course_id=:semester_course_id, emp_mas_staff_id=:emp_mas_staff_id, emp_category=:emp_category 

    insert into staff_assign 
    (`main_course_id`, `main_batch_id`, `section`, `semester_course_id`, `emp_mas_staff_id`, `emp_category`) 
    SELECT * FROM (
        SELECT 
        :main_course_id, :main_batch_id, :section_id, :semester_course_id, :emp_mas_staff_id, :emp_category
    ) AS tmp WHERE NOT IN (
        SELECT emp_mas_staff_id FROM staff_assign WHERE emp_mas_staff_id = $save_emp_mas_staff_id
    ) LIMIT 1
  </code>

请向我发送查询以解决此问题。

以上是我的疑问。

我找到了上述问题的答案。

mysql.proc 问题。

在我的 mysql 中,我的 mysql.proc 已损坏。这就是它不执行上述查询的原因。

要解决上述问题,您需要在 linux 中更新 mysql。