Skip to content
Advertisement

How to select an element just once in plain SQL

I’ve seen other similar questions to mine, but I haven’t found one that could actually help me. I have a table, defined like so:


This DDL comes from an OracleDB12 database.
Following, some sample data

enter image description here

What I’d like to accomplish: if there’s already a row with the same tuple (IDRFX, DOCNUM), not including it in the SELECT statement. So, the tuple (384,1) should appear only once.


What I’ve done (so far): with the idea that this query could be performed even from a MSSQL database, I’ve tried to write these two queries in plain SQL.

But none of them was actually able to get me anywhere. If possible, I’d like to ask where am I doing the mistake and how can I fix it.

Advertisement

Answer

You can use row_number analytical function as follows:

OR you can use the NOT EXISTS query as follows:

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement