I have the following query. Currently it checks on two conditions:
- if one condition is true it will return the results for the first statement
(t1.ticket=t2.ticket and ( t1.type=t2.type)
- if this result is false then it will return results for the next condition
( t1.code=t2.code)
.
It does this is because sometimes this condition columns (t1.ticket=t2.ticket and ( t1.type=t2.type))
are equal to null and some times this condition colums ( t1.code=t2.code)
are null thats why it switches between both.
But now what i noticed is that sometimes both the conditions return true and because of the OR
statement its ignoring one of the conditions.
How do i return results for both of those conditions if they both there conditions are met? If its not met then they must return the one condition that matches.
select t1.name
,t1.ID
,t1.type
,t2.TicketID
,t2.Account
,t1.code
from table 1 t1
inner join table 2 t2
on (t1.ticketID=t2.ticketID and t1.type=t2.type)
or ( t1.code=t2.code)
left join table 3 t3
on t2.Res=t3.res
left join table 4 t4
on t3.IdDetail=t4.idDetail