Skip to content
Advertisement

How to use Distinct OR Group by with Inner Join?

have a problem with sql query, simple one but though I’m sitting on it 3d day and cant figure out what is wrong, please help.

Table 1: enter image description here

Table 2

enter image description here

Result enter image description here

Desired result – in my reslt I want to display each portfolio ID ONLY ONCE.

sql query:

Any ideas / solutions are welcomed. Thank you

Advertisement

Answer

Use row_number():

EDIT:

In older versions, if you want just one column from portfolio_images you can use a correlated subquery:

As for your query, DISTINCT applies to all columns, so clearly different columns have different values, even if the columns from portfolio are the same.

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