By ak4784


2016-12-22 13:40:15 8 Comments

Can somebody tell me how I can convert the following Oracle SQL Statement in Postgres SQL? I don't get it...

SELECT MIN(t2.id) KEEP (DENSE_RANK FIRST ORDER BY t2.edit_date) AS id 
  FROM temp t2 
 GROUP BY t2.sku

1 comments

@Gurwinder Singh 2016-12-22 13:44:27

SELECT MIN(t2.id) OVER (ORDER BY t2.edit_date) AS id 
FROM temp t2 
GROUP BY t2.sku

EDIT:

Even though above did what OP asked, the equivalent for the given query can be:

select min(t.id) id 
from
  (select t.*,
   dense_rank() over (order by t.edit_date) AS rnk 
   from temp t) t
where rnk = 1
group by t.sku;

@ak4784 2016-12-22 13:53:40

This worked for me - thanks. But I needed to add the other columns in the Group by

@Gurwinder Singh 2016-12-22 13:54:32

Please post the data and expected output in question and we'll be able to help you on that

@mathguy 2016-12-22 14:29:32

This is odd... isn't this an analytic function in PostgreSQL, just like in Oracle? If it is, then it's not the equivalent of the Oracle statement in the original question. (But hey, the OP thinks it is, so why argue...)

@ak4784 2016-12-23 07:23:25

You are right - I was too fast. The edited question is correct. It's just a part of a statement. I delete all duplicated products except the oldest. And this part of the Statement should deliver me the oldest one.

Related Questions

Sponsored Content

29 Answered Questions

[SOLVED] How to select the nth row in a SQL database table?

18 Answered Questions

[SOLVED] psql: FATAL: database "<user>" does not exist

  • 2013-07-13 19:18:24
  • Ryan Rich
  • 292647 View
  • 624 Score
  • 18 Answer
  • Tags:   postgresql psql

14 Answered Questions

[SOLVED] Select first row in each GROUP BY group?

7 Answered Questions

[SOLVED] postgres: upgrade a user to be a superuser?

  • 2012-05-25 15:43:18
  • flossfan
  • 296791 View
  • 615 Score
  • 7 Answer
  • Tags:   sql postgresql

20 Answered Questions

[SOLVED] Get list of all tables in Oracle?

  • 2008-10-15 17:54:49
  • vitule
  • 2096711 View
  • 1061 Score
  • 20 Answer
  • Tags:   sql oracle

17 Answered Questions

[SOLVED] Postgres: INSERT if does not exist already

7 Answered Questions

[SOLVED] Select statement to find duplicates on certain fields

11 Answered Questions

[SOLVED] SQL Server: How to Join to first row

1 Answered Questions

Oracle DENSE_RANK()

1 Answered Questions

[SOLVED] Convert keep dense_rank from Oracle query into postgres

Sponsored Content