sql语句查询数据是和三张表有关联的应该怎么写?
发布网友
发布时间:2022-05-04 16:20
我来回答
共3个回答
热心网友
时间:2022-06-24 00:11
select
a.*,b.*,c.*
from
a
inner
join
b
on
a.a1
=
b.b1
left
join
c
on
a.a2
=
c.c2
where
a.a1='xx'
主要用标准sql的inner
join
,left
join
,right
join
进行连接,左连,右连;
on
后面可以加括号,加其他条件,也可以用括号来确定先连接哪个再连接哪个
热心网友
时间:2022-06-24 00:11
select
School.SchoolID,Student.StudentName
from
School
full
join
Class
on
School.ClassId=Class.ClassId
full
join
Student
on
Class.StudentId=Student.StudentId
要查找的东西放在最上面,然后连接表,连接条件。就这样。
热心网友
时间:2022-06-24 00:12
select
School.SchoolID,Student.StudentNamefrom
Student
left
join
Class
on
Student.StudentId
=
Class.Student
left
join
School
on
Class.ClassId
=
School.ClassId