Skip to content
Advertisement

SQL select min() using SQL join

I need result like this (in Oracle SQL):

and I can get it with this SQL

or with this:

But I am trying to get that result using SQL JOINS, like this:

But it doesn’t produce desired result, it outputs all products and producers prices. Any help with this?

DDL is:

Advertisement

Answer

The issue isn’t the join. It is the selection of the best row. To get the best row use row_number() (chooses arbitrarily if the “best” is duplicated) or rank() (choose all best when there are duplicates).

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