【问题标题】:combine selected columns from two tables and store it in another table in the db合并两个表中的选定列并将其存储在数据库中的另一个表中
【发布时间】:2014-01-02 06:39:28
【问题描述】:

您好,我想合并两个表中的选定列并将这些值存储到另一个表中。

例如我有一个表名

class - classname location

还有一张桌子

student - studentid, name, classname

出勤率 - 仅将两个表合并到选定的列。

i.e studentid , classname, location

告诉如何将值插入到我的表出勤率中。

在此先感谢...

【问题讨论】:

    标签: mysql sql select join insert-select


    【解决方案1】:

    你应该使用INSERT...SELECT

    INSERT INTO Attendance (studentid , classname, location)
    SELECT s.studentid, c.classname, c.location
    FROM class c 
    INNER JOIN student s ON c.classname = s.classname 
    

    【讨论】:

      猜你喜欢
      • 2019-04-23
      • 2012-06-11
      • 1970-01-01
      • 2010-09-22
      • 2018-06-23
      • 2019-10-28
      • 1970-01-01
      • 1970-01-01
      • 2015-10-29
      相关资源
      最近更新 更多