Skip to content
Advertisement

How to deselect duplicate entries in a query?

I’ve got a query like this:

and this query returns the result like this:

query result

As you can see in the image there is 3 duplicate, unnecessary entries (no, i can’t delete them because of the multiple foreign keys). How can I deselect these duplicate entries from the result query? In the end I want to return 6 entries not 9.

Advertisement

Answer

What you want to eliminate in the result set is not duplication of recipe_id values but recipe_name values.

You just need to group(partition) by recipe_name through use of ROW_NUMBER() analytic function :

This way, you can pick only one of the records with rn=1 (ORDER BY Clause might be added to that analytic function after PARTITION BY clause if spesific record is needed to be picked)

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