0

I have written a SQL query to display results, the below is the query

SELECT TRANSACTION_ID, INVOICE_NO, MOBILE_NO, ITEM_AMOUT
FROM INVOICE_DAILY_DTS
WHERE DAILY_DTS != 200 AND INVOICE_SAM = 12;

When I am executing the above query, I am getting the below results

1) 11331133114, 154245, 077123456789, 579.5
2) 11331133114, 154245, 077123456789, 579.5
3) 11331133114, 154246, 077457852155, 780.4
4) 11331133114, 154245, 077123456789, 579.5
5) 11331133114, 154458, 077547822554, 900.0
6) 11331133114, 154245, 077123456789, 579.5
7) 11331133114, 154246, 077457852155, 780.4

If you see the above results table has multiple rows of data in the INVOICE_NO column, I suggest getting ignore 2,4,6 & 7th rows when executing the query. Simple if the INVOICE_NO is duplicated only needs to get the first row of the result and ignore other results.

I am expecting the results are below, where it has ignored or excepted the results and showing the first row only of each INVOCIE_NO

1) 11331133114, 154245, 077123456789, 579.5
2) 11331133114, 154246, 077457852155, 780.4
3) 11331133114, 154458, 077547822554, 900.0
flyingfox
  • 13,414
  • 3
  • 24
  • 39
Gohulan
  • 1
  • 1
  • 1
    Does this answer your question? "[Duplicate rows in Oracle](/q/816851/90527)", "[How do I prevent the loading of duplicate rows in to an Oracle table?](/q/1588588/90527)", "[Removing duplicate rows from table in Oracle](/q/529098/90527)", "[Identifying duplicates in a table without index](/q/2495552/90527)" – outis Oct 08 '22 at 03:39

2 Answers2

0

Try:

SELECT DISTINCT INVOICE_NO, TRANSACTION_ID, MOBILE_NO, ITEM_AMOUT
FROM INVOICE_DAILY_DTS
WHERE DAILY_DTS != 200 AND INVOICE_SAM = 12;
YUNG FOOK YONG
  • 109
  • 1
  • 11
0

You can use row_number() to do it

SELECT t.TRANSACTION_ID, t.INVOICE_NO, t.MOBILE_NO, t.ITEM_AMOUT
 FROM
 (
  SELECT TRANSACTION_ID, INVOICE_NO, MOBILE_NO, ITEM_AMOUT,
   ROW_NUMBER() OVER (PARTITION BY INVOICE_NO) rn
 FROM INVOICE_DAILY_DTS
 WHERE DAILY_DTS != 200 AND INVOICE_SAM = 12
 ) AS t
WHERE t.rn=1
flyingfox
  • 13,414
  • 3
  • 24
  • 39