求一查询语句!

tianlei521 2006-11-22 02:05:12
两个表需要用字段dabh进行关联查询,语句如下:
select a.*,b.gly from table1 a,table2 b where a.dabh=b.dabh
但问题是由于录入等原因,table1中的dabh字段有些记录跟table2中的dabh字段不一致,上述查询语句只能查询两个dabh字段一致的记录,不一致的查不出来,导致了查询出来的记录条数不对,如何才能将table1中的全部记录查出来,不管能不能对应起来。
...全文
152 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
tianlei521 2006-11-22
  • 打赏
  • 举报
回复
谢谢大家!
目目 2006-11-22
  • 打赏
  • 举报
回复
自己查一查left join和right join、join的用法就知道了
userqin 2006-11-22
  • 打赏
  • 举报
回复
试试
select a.*,b.gly from table1 a left join table2 b on a.dabh=b.dabh
zzxiaoma 2006-11-22
  • 打赏
  • 举报
回复
select table1.*,table2.gly from table1 left join table2 on table1.dabh=table2.dabh
dulei115 2006-11-22
  • 打赏
  • 举报
回复
select a.*,b.gly
from table1 a left join table2 b on a.dabh=b.dabh

34,590

社区成员

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

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