我在SQL中使用(加入)时出现一些错误

时间:2019-03-10 11:15:26

标签: sql

我正在尝试在SQL中使用join on在三个表之间进行链接,但仍然有错误

enter image description here

当我尝试检索时:  (阿米娜的讲师和主题) 我这样做了,但仍然有错误

 SELECT c.SUBJECT1,c.SUBJECT2,c.SUBJECT3,l.NAME
FROM
  STUDENT s 
  JOIN COURSE c
   ON c.COURSE = s.COURES
   JOIN LECTURER l
   ON l.LECT_ID =c.LECT1 AND c.LECT2 AND c.LECT3 
WHERE s.NAME = 'Aminah' AND c.SUBJECT1 = c.LECT1 AND c.SUBJECT2 = c.LECT2 AND c.SUBJECT3 = c.LECT3 

当我尝试显示时也是如此: (由艾哈迈德教授的主题) 我是一个初学者,使用(join on)仍然对我来说仍然很困难 我希望有人能帮助我

1 个答案:

答案 0 :(得分:0)

我认为您想要多个联接,例如:

select c.subject1, c.subject2, c.subject3,
       l1.name as name_1, l2.name as name_2, l2.name as name_2
from student s join
     course c
     on s.course = c.course left join
     lecturer l1
     on c.lect_1 = l1.lect_id left join
     lecturer l2
     on c.lect_2 = l2.lect_id left join
     lecturer l3
     on c.lect_3 = l3.lect_id
where s.name = 'Aminah';

您还应该知道这是一个非常糟糕的数据模型。每当您具有分布在各列中的“数组”(例如课程)时,它就很可疑。这些实际上应该放在单独的行中,以更好地适合SQL。