我想将表主题,参考,教学大纲中的主键复制到表Reference_Subject中。这不起作用:
INSERT INTO REFERENCE_SUBJECT (REFERENCE_ID,SYLLABUS_ID,SUBJECT_ID)
(SELECT REFERENCE_ID FROM REFERENCE
, SELECT SYLLABUS_ID FROM SYLLABUS
, SELECT SUBJECT_ID FROM SUBJECT);
错误是
表名无效
答案 0 :(得分:0)
我真的认为你需要加入REFERENCE, SYLLABUS, SUBJECT
INSERT INTO REFERENCE_SUBJECT
(REFERENCE_ID,SYLLABUS_ID,SUBJECT_ID)
SELECT REFERENCE_ID ,SYLLABUS_ID, SUBJECT_ID
FROM REFERENCE, SYLLABUS, SUBJECT;
答案 1 :(得分:0)
使用select distinct,否则你获得重复的行做连接表格REFERENCE,SYLLABUS,SUBJECT
无论如何你还要加入3张桌子......不知道加入你可以
INSERT INTO REFERENCE_SUBJECT (REFERENCE_ID,SYLLABUS_ID,SUBJECT_ID)
SELECT DISTINCT REFERENCE_ID SYLLABUS_ID SUBJECT_ID
FROM REFERENCE, SYLLABUS, SUBJECT;