使用Left outer join和where [英] Using Left outer join and where

查看:65
本文介绍了使用Left outer join和where的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨。

这里我有两张桌子tblBonusMaster和tblComboDetails



tblBonusMaster



boID描述boBonusMode

---- ----------- -----------

1 200每日

2 100每年

3 1000 0

4 150 0



tblComboDetails



cdClass cdText cdValue

------- ------ -------

BonusMode每日每日

BonusMode每周每周

BonusMode每年每年





这里我想得到第一个表(即tblBonusMaster)的所有字段值,包括包含cdClass的tblBonusMaster的第3行和第4行(即本例中的奖励模式)



以下是我的查询



SELECT tblBonusMaster。*,tblComboDetails。*
来自tblBonusMaster的

在tblBonusMaster.boBonusMode = tblComboDetails.cdValue上加入tblComboDetails

其中tblComboDetails.cdClass = ''奖金模式''







使用此查询我只获得第1和第2行tblBonusMaster。包含零的行未显示。如何获取第一个表的所有行

Hi.
Here i have two tables tblBonusMaster and tblComboDetails

tblBonusMaster

boID Description boBonusMode
---- ----------- -----------
1 200 Daily
2 100 Yearly
3 1000 0
4 150 0

tblComboDetails

cdClass cdText cdValue
------- ------ -------
BonusMode Daily Daily
BonusMode Weekly Weekly
BonusMode Yearly Yearly


here i want to get all the field values of the first table(ie tblBonusMaster) including the 3rd and 4th row of the tblBonusMaster containing the cdClass (ie Bonus Mode in this case)

below is my query

SELECT tblBonusMaster.*,tblComboDetails.*
from tblBonusMaster
left join tblComboDetails on tblBonusMaster.boBonusMode=tblComboDetails.cdValue
where tblComboDetails.cdClass=''Bonus Mode''



using this query Im only getting the 1st and 2nd row of tblBonusMaster. the row containing zero are not getting displayed. How can i get all the rows of the first table

推荐答案

SELECT tblBonusMaster.*,tblComboDetails.*
from tblBonusMaster
left join tblComboDetails on tblBonusMaster.boBonusMode=tblComboDetails.cdValue;





你正在使用导致麻烦的地方



you are using where that causing the trouble


你的查询是对的。我不能得到第3和第4行,因为

ur使用condition tblBonusMaster.boBonusMode = tblComboDetails.cdValue so

它将显示两个表的匹配数据。所以你应该改变条件。
your query is right .u cant get 3 and 4th row because
u r using condition tblBonusMaster.boBonusMode=tblComboDetails.cdValue so
it will display match data of both table . so u should change condition .


这篇关于使用Left outer join和where的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆