I am using SQL Server 2008 and have the following scenario:
I have Table a with fields id and groupId.
I have Table b with fields id and groupId also.
The rule in Table b, is that:
If a.id = 0, then a.groupId = b.groupId
Else a.id = b.id (in which case a.groupId = 0)
The 2 tables are also linked by agrId such that a.agrId = b.agrId
How can I join these tables, whilst satisfying the rule above?
Update: Apologies for the lack of clarity, I have updated the rule and added my attempt below:
select * from a
inner join b
on a.agrId = b.agrId
where (
    (b.id > '0' and b.groupId = '0') 
    or
    (b.groupId > '0' and b.id = '0')
  )
 
     
     
    