I am trying to create a temp table in SQL by joining 2 existing temp tables. My tables look like:
I'm trying to join the two tables. But if I do a left join, it gives me a lot of duplicate rows and the table looks like this:
As you can see, the data in red is duplicated and only the data in first row is unique. My code is below:
select
CMO.CUSIP,
CMO.LEVEL1,
CMO.COUPON,
CMO.TRANCHE_GROUP as 'Tranche Group',
CMO.TRANCHE_TYPE as 'Tranche Type',
CMO.price as 'Current Price',
CMO.PREV_PRICE as 'Previous Price',
CMO.price_dec as 'Color',
cast (CMO.DataDate as date) as 'Color Date',
CMO.dealer as 'Dealer',
CHA.Challenge_Date,
CHA.Challenge_Price,
CHA.Updated_Price,
CHA.Client_Name,
CHA.Evaluator,
CHA.Accepted,
CMO.DATA_DATE
into #cmodatatable
from
#cmocolortemptable CMO
left join #challengetemptbl CHA on CMO.CUSIP = CHA.CUSIP1
select *
from #cmodatatable
Is there a way to avoid this? I'm trying to get an output like this:
I'm exporting this data into Tableau, and counting the distinct values in Tableau is becoming very tedious, that's why I'm trying to do it in SQL and then take the data to Tableau. I think I might have to do a union but since the data is different in the tables, I don't know how I'll do a union. Any help is appreciated in this regard. Thank you!