My Data
is returning result with multiple result with cd.Id2, I would like cd.Id2 to be distinct. If Data result has five cd.Id2 there are the same I would like to only get the first result of every duplicated cd.Id2.
> SELECT Id
> ,IsIncluded
> ,LineId
> ,LineType
> ,LineNumber
> ,LineDescription
> ,SUM(table2.StartBalance) AS StartBalance
> ,SUM(table1.MoneyIn) AS MoneyIn
> ,SUM(t1.MoneyOut) AS MoneyOut
> FROM Data AS table1
> LEFT JOIN StartBalanceData table2 ON table1.Id2 = table2.Id
Comments:
Data multiple of same ID (join on first)
StartBalanceData to map with ID
> GROUP BY Id, IsIncluded, LineId, LineType, LineNumber, LineDescription
I tried using LIMIT 1. but it is not supported.
IMAGE OF EXPECTED RESULT
1条答案
按热度按时间2g32fytz1#
You could do an OUTER APPLY instead which gets one row only:
Since you were helpful enough to avoid cluttering your question with details like testdata or about which balance data you want to preferably fetch, it's hard to write a complete query, but perhaps this might get you started