I am using SQL Server 2014 and I have these 2 tables to join so as to get the output shown below.
Table 1 (ResStayDate):
ResID StayDate PlanCode Rateamount
150 2015-08-07 UKHB 124.00
150 2015-08-08 UKHB 124.00
150 2015-08-09 UKHB 124.00
176 2015-09-10 FRAI 98.00
176 2015-09-11 FRAI 98.00
188 2015-10-03 GRHB 29.00
188 2015-10-04 GRHB 29.00
188 2015-10-05 GRHB 29.00
Table 2 (ResStay):
ResID CurrencyCode Status
150 GBP OK
176 EUR CANCELED
188 EUR OK
I need the following output:
ResID StayDate PlanCode Rateamount CurrencyCode Status
150 2015-08-07 UKHB 124.00 GBP OK
150 2015-08-08 UKHB 124.00 GBP OK
150 2015-08-09 UKHB 124.00 GBP OK
188 2015-10-03 GRHB 29.00 EUR OK
188 2015-10-04 GRHB 29.00 EUR OK
188 2015-10-05 GRHB 29.00 EUR OK
This how my query looks as at now (but it's not giving the output above):
Use MyDatabase
Select a.ResID
,a.StayDate
,a.PlanCode
,a.Rateamount
,b.CurrencyCode
,b.Status
FROM ResStayDate a
LEFT JOIN ResStay b ON a.ResID = b.ResID
WHERE b.Status <> 'CANCELED'
I can't figure out why it's not giving me the output I'm after. It is giving me the fields (columns) I need but it is duplicating the rows many times. Is it a JOIN syntax issue? I've tried INNER JOIN but that also did not work.
INNER JOIN