Tuesday 8 August 2017

Ambil record pertama dari setiap ID pada query ORDER BY

Status : Draft



Bagaimana kita mengambil id_soal pertama dari setiap kelompok id_soal ? Solusinya bisa intip di [1]

Atau contoh lain :

WITH par AS (
 SELECT ROW_NUMBER() OVER (PARTITION BY id_paragraph) AS rn, id_paragraph
                           FROM paragraph_soal WHERE id_paragraph='2013 (A.11)20-22'
)
SELECT  * from par where rn = 1;


Referensi 


  1. PostgreSQL: Select only the first record per id based on sort order, https://stackoverflow.com/questions/18987650/postgresql-select-only-the-first-record-per-id-based-on-sort-order

No comments:

Post a Comment