Search code examples
sqlsql-serverjoinfull-outer-join

Matching and unlatching records in a single table sql server


I have procedure where I am getting data from my 1st temp table like below

enter image description here

2nd temp table like below

enter image description here

Now I need to join this 2 temp tables to get all matching and unmatching data .My result would be like below

enter image description here

enter image description here

But I am getting only matching data.Please help how to do


Solution

  • I think that's a full join:

    select 
        coalesce(t1.agentName, t2.agentName) agentName,
        coalesce(t1.completedTickets, 0) completedTickets,
        coalesce(t2.activeTickets, 0) activeTickets
    from t1
    full join t2 on t2.agentName = t1.agentName