如何插入一行,来自其他 table 的值?

How to insert into a row, a value from other table?

我有 3 个 Mysql table。

A table 带有 类 和实验室及其 ID。

A table teachers_list 和他们的主题。 A table 这将是时间表。**

我想在我的第三个 table 中随机分配一名物理学家到其中一个物理实验室,这将是时间表。

INSERT INTO schedule(teacher_name, class_id)
VALUES (select teacher_name from teachers_list where subject="Physicist” order by rand() limit 1, 

select id from lab_list where lab="Physics_lab" order by rand() limit 1);

**这个不行:(

你能帮帮我吗?**

我认为您需要 insert ... select 语法以及子查询:

insert into schedule(teacher_name, class_id)
select 
    (
        select teacher_name 
        from teachers_list 
        where subject = 'Physicist'
        order by rand()
        limit 1
    ),
    id
from lab_list
where lab = 'Physics_lab'