三个以上的表JOIN起来,SQL语句应该怎样写?

CTBOK 2003-09-19 10:59:23
谢谢
...全文
6785 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
applexml 2003-09-19
  • 打赏
  • 举报
回复
假设a:主表,b,c是从表
字段:
a_b_id 对应b_id;
a_c_id对应c_id

select * from a
left outer join b on a.a_b_id = b.b_id
left outer join c on a.a_c_id = c.c_id

这样,保证a表的所有记录都至少出现一次
Wally_wu 2003-09-19
  • 打赏
  • 举报
回复
select b1, b2, b3 from table1 join table2 on a1=a2 join table3 on a1=a3 where a1 not null
junsisi 2003-09-19
  • 打赏
  • 举报
回复
select * from a inner join b on a.id=b.id inner join c on a.id=c.id
CTBOK 2003-09-19
  • 打赏
  • 举报
回复
但如果是一表的两个字段对应另外两个表呢?
就是一对二的关系,应该怎样写?
pengdali 2003-09-19
  • 打赏
  • 举报
回复
select * from a join b on a.id=b.id join c on a.id=c.id
sunruping 2003-09-19
  • 打赏
  • 举报
回复
select * from a inner join b on b.x=a.x inner join c on c.x=b.x
friendliu 2003-09-19
  • 打赏
  • 举报
回复
USE pubs
SELECT a.au_lname, a.au_fname, t.title
FROM authors a INNER JOIN titleauthor ta
ON a.au_id = ta.au_id JOIN titles t
ON ta.title_id = t.title_id
WHERE t.type = 'trad_cook'
ORDER BY t.title ASC
CTBOK 2003-09-19
  • 打赏
  • 举报
回复
我是说JOIN,有条件的JOIN,比如他们之间某一个字段有关联,哪位朋友有示例语句?谢谢
junsisi 2003-09-19
  • 打赏
  • 举报
回复
select a.*,b.*,c.* from a,b,c
mayupeng 2003-09-19
  • 打赏
  • 举报
回复
select t1.age,t2.name,t3.tel from t1,t2,t3
where t1.id=t2.id and t2.id=t3.id

34,593

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧