通过比较来自不同表的两个其他字段将不同的字段插入表中

时间:2018-05-07 03:57:52

标签: php jquery sql

Form built with HTML AND CSS

CREATE TABLE surgery (
    surgery_id INT AUTO_INCREMENT PRIMARY KEY,
    doc_id INT NOT NULL REFERENCES doctor(doc_id),
    nurse_id INT NOT NULL REFERENCES nurse(nurse_id),
    surgery_status VARCHAR(8) NOT NULL CHECK (surgery_status IN (`Success`, `Fialled`)),
    description NVARCHAR(200) NOT NULL
)  ENGINE=INNODB CHARSET=UTF8 COLLATE UTF8_BIN;

手术台上有患者ID和医生ID,分别与患者台和医生台相关联。我想用表格收集患者和医生的姓名,但是将他们的身份而不是他们的名字插入手术台。

1 个答案:

答案 0 :(得分:0)

您可以将子查询概念用于此类方案。 示例:

SELECT *,(SELECT patient_name FROM patient WHERE patient.id = surgery.patient_id) AS _patient_name,
(SELECT doctor_name FROM doctor WHERE doctor.id = surgery.doctor_id) AS _doctor_name FROM surgery