Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi every one.

I have two Tables, that i need join them in left. But in second Table i have a Language field that i named it "Lang" , Like this :

Table1 : (id,a,b,c,...)
Table2 : (id,Table1ID,a,b,Lang,...)

I need left join in any language, but i need if there was not any row in Table2, or EVEN there was rows in Table2 but for another languages but I NEED Table1 fields in any case.

I have this now :

SQL
Select * From  [dbo].[TUniqueProduct]  TUP
Left Join TUniqueProductItems TUPI
On TUP.ProductID = TUPI.ProductPID
where TUP.ProductGuID = 1000 AND  (Lang = 1 OR Lang IS NULL)
order by RowOrder, ProductID DESC


It show me left part when there is row in Table2 for this lang,or there is not any row for this ID.
BUT it can not show me left side if there is rows for another languages. in this case i need left part and null for right part fields.

Any suggestion?
Thanks in advance.
Posted

1 solution

The query works as expected. If you need result for all the languages, but shown as null, then you need to change the join condition On TUP.ProductID = TUPI.ProductPID AND (Lang = 1 OR Lang IS NULL)
 
Share this answer
 
Comments
arminamini 14-Nov-11 8:00am    
Great!
Thank you very much. it worked.
Prerak Patel 14-Nov-11 8:01am    
You are welcome.

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