sql怎么查询2个表以上的信息?内联外联?

来源:百度知道 编辑:UC知道 时间:2024/09/24 23:36:29
``请求详细方法
2个以上,3个以上,4个以上

如,两个表的连接语句
Select student.*,sc.*
From student,sc
Where student.sno=sc.sno
如,三个表的连接语句
Select sno,sname
From student
Where sno in
(select sno
from sc
where cno=
(select cno
from course
where cname='信息系统'))

select student.sno,sname
from student,sc,course
where student.sno=sc.sno and sc.cno=course.cno and course.cname='信息系统'
四个表的同理

如何进行多表的连接!
可以使用INNER JOIN 或者 LEFT JOIN , RIGHT JOIN等进行

例如内连接 tableA INNER JOIN tableB on join_condition
或者交叉联接 tableA cross join tableB等很多!

连接2个以上的表:
例如:
select buyer_name,prod_name,qty
from buyers
inner join sales
ON buyers.buyer_id=sales.buyer_id
inner join produce
ON sales.prod_id=produce.prod_id
Go

简单的可以用
select a.name,b.age from 表A a,表B b where a.id=b.id
二个,三个以上也可以的嘛....
select a.name,b.age,c.sex from 表A a,表B b,表C c where