Pawan Agrawal
Pawan Agrawal

Reputation: 283

sql server query to get records from multiple tables

I have two tables in sql server and I want result like below -

enter image description here

There is a column LabelName in both the tables. And I need records on the basis of that column. There are two tables for two different languages with same LabelName.

So can any one help me out on this.

Upvotes: 0

Views: 123

Answers (1)

M. Grue
M. Grue

Reputation: 331

You can use a FULL OUTER JOIN for that with some CASE, to get the result, look at: http://www.w3schools.com/sql/sql_join_full.asp and https://msdn.microsoft.com/en-us/library/ms181765.aspx

So what you need is this:

SELECT 
  CASE WHEN e.LabelId IS NULL THEN t.LabelId ELSE e.LabelId END AS LabelId
, CASE WHEN e.LabelName IS NULL THEN t.LabelName ELSE e.LabelName END AS LabelName 
, e.LabelText AS LabelText_English
, t.LabelText AS LabelText_Tamil
FROM TBL_English AS e
FULL OUTER JOIN TBL_Tamil AS t ON e.LabelId = t.LabelId

Upvotes: 1

Related Questions