Situation :
In a table there is a list of items with their invoiced invoice amounts. This table has a single field that varies according to the insertion of the data, being able to repeat all the other columns and does not have a PK
. An example would be:
fk_nota_fiscal | fk_produto | valor | campo2 | campoXXX
244060 | 0010101 | 100,00| X | A
244060 | 0010101 | 100,00| X | B
244060 | 0010101 | 100,00| X | C
Desired :
I need to get only the first result regardless of the variation of the campoXXX
column.
Problem encountered:
Using the functions ROW_NUMBER()
and OVER()
, I aggregated the results into a CTE
and managed to select only the first result, but performance is absurdly slow and unfeasible for a considerable amount of records.
ROW_NUMBER() OVER(PARTITION BY fk_nota_fiscal,fk_produto ORDER BY fk_nota_fiscal,fk_produto) AS ROWID
SELECT * FROM FROM CTE_vwItensRefaturar WHERE ROWID = 1