select distinct
tests the ENTIRE row to see if it is unique. Just the smallest little difference in any column will make a row "distinct". The following 2 values are different, so that will cause 2 rows
- 741722064100000
- 741-722-06-41-00000
and the following 2 value pairs are different, which cause 2 more rows:
- 500000 800000
- 435000 850000
in all that combines to make 4 rows.
So, it looks like we could strip the dash from data item 2 above, and that would make it equal data item 1.
replace(t.parcel,'-','') AS [Parcel#]
But is that always true? Could there be other differences in other rows not shown here?
How do we decide between the value pairs 3. or 4. ? MAX()
won't work e.g.
MAX(c.mv_30day_value), MAX(c.mv_30day_repvalue)
would produce
500000 8500000
and that combination doesn't exist in the source data
The logic required to meet the expected result isn't well defined.
Try the following:
SELECT
x.[PropertyBasics.PK Resnet Property ID]
, x.filname
, MAX(c.mv_30day_value) "30 Day Value As Is"
, MAX(c.mv_30day_repvalue) "30 Day Value Repaired"
, replace(t.parcel,'-','') "Parcel#"
-- , x.* NO WAY !!
FROM Resnet_Reporting_ops.dbo.Ops_FullExportFLATV3 AS X
LEFT JOIN resnet_mysql.dbo.form_tax t ON x.[PropertyBasics.PK Resnet Property ID] = t.property_id
LEFT JOIN resnet_mysql.dbo.form_fm c ON t.task_id = c.task_id
WHERE X.[PropertyBasics.Property Basics - ResID] = 217
AND x.[PropertyBasics.PK Resnet Property ID] = 1153829
GROUP BY
x.[PropertyBasics.PK Resnet Property ID]
, x.filname
, replace(t.parcel,'-','')
;
Note. x.*
isn't feasible with GROUP BY as you need to specify the columns will define each unique row. x.*
is also counter productive with "select distinct" as for each additional column of output you increase the possibility of more rows. (i.e. more columns generally = more differences = more rows). Also as mentioned doubt MAX() produces a good result here.