Nassim
Nassim

Reputation: 117

SQL Server - Join two tables with not the same values

I begin with SQL. I have two tables and I want to join them.

In table A, I have a column Business with two possible values: Ins or Rea.

In table B, I have a column Outward with two possible values: 1 or -1.

Knowing that 1 = "Ins" and -1 = "Rea", do you have a query which can help me to join these two tables?

Upvotes: 0

Views: 678

Answers (1)

WAMLeslie
WAMLeslie

Reputation: 1261

It's not much to go on since I don't know if you have any foreign keys or references in the tables. But you could use a JOIN with a CASE if all you have is what's in the question above and there are no other values.

select *
from business b
join outward o
    on b.[value] = case when o.[value]=1 then 'Ins' 
                        when o.[value]=-1 then 'Rea'
                        end

Upvotes: 5

Related Questions