Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
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
Posted

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


you are using where that causing the trouble
 
Share this answer
 
Comments
Nihal Hussain 18-Jan-13 0:55am    
@Hasham Ahmad. I want the 3rd and 4th row also along with 1st and 2nd. So whats the condition i should put
[no name] 18-Jan-13 1:19am    
no condition ... run the query ... it will give you the results
[no name] 18-Jan-13 1:29am    
just checked it using http://sqlfiddle.com/#!3/518d9/3
it gives the result according to the requirements.
only if i have understood your problem
Nihal Hussain 18-Jan-13 1:50am    
@Hasham Ahmad In that Link Im getting it. but what if i add another cdClass say cdClass='Bonus Type' but condition I wil give is where cdClass='Bonus Mode' then how can i get the 3rd and 4th row of tblBonusMaster which has bobonusMode value as 0.
[no name] 18-Jan-13 1:59am    
the same query will do :s
i dont think adding bonus mode to cdclass will have any effect on the query
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 .
 
Share this answer
 
Comments
Nihal Hussain 18-Jan-13 0:55am    
@solanki.net. I want the 3rd and 4th row also along with 1st and 2nd. So whats the condition i should put
solanki.net 18-Jan-13 1:06am    
If u add id column in tblComboDetails table then apply join on id column then u can get 3rd row but not 4th row because your second table has only 3 record .if your second table (tblComboDetails ) has four record then u can get 3rd and 4th row also.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900