title: Oracle SQL, how to select first row in a group?
body: <p>Here is the my SQL fiddle: <a href="http://sqlfiddle.com/#!4/75ab7/2" rel="nofollow noreferrer">http://sqlfiddle.com/#!4/75ab7/2</a></p>
  
  <p>Basically, I have created a table and insert some data into it.</p>
  
  <pre><code>CREATE TABLE subject (
    id INT NOT NULL,
    seq_num INT NOT NULL,
    name VARCHAR(30) NOT NULL
  );
  
  INSERT INTO subject 
    (id, seq_num, name) 
  VALUES 
    (1, 1, 'sub_1_1');
  
  INSERT INTO subject 
    (id, seq_num, name) 
  VALUES 
    (2, 1, 'sub_1_2');
  
  INSERT INTO subject 
    (id, seq_num, name) 
  VALUES 
    (3, 2,'sub_2_1');
  
  INSERT INTO subject 
    (id, seq_num, name) 
  VALUES 
    (4, 2, 'sub_2_2');
  
  INSERT INTO subject 
    (id, seq_num, name) 
  VALUES 
    (5, 2, 'sub_2_3');
  
  INSERT INTO subject 
    (id, seq_num, name) 
  VALUES 
    (6, 3, 'sub_3_1');
  
  INSERT INTO subject 
    (id, seq_num, name) 
  VALUES 
    (7, 3, 'sub_3_1');
  </code></pre>
  
  <p>I run this select statement:</p>
  
  <pre><code>select
    LISTAGG(TRIM(id), ',') WITHIN GROUP (ORDER BY 1) AS IDS,
    seq_num,
    LISTAGG(TRIM(name), ',') WITHIN GROUP (ORDER BY 1) AS NAMES
  from
    subject
  group by
    seq_num
  order by
    seq_num asc
  </code></pre>
  
  <p>The select statement result:</p>
  
  <pre><code>| ids   | seq_num | names                   |
  |-------|---------|-------------------------|
  | 1,2   | 1       | sub_1_1,sub_1_2         |
  | 3,4,5 | 2       | sub_2_1,sub_2_2,sub_2_3 |
  | 6,7   | 3       | sub_3_1,sub_3_1         |
  </code></pre>
  
  <p>Can I generate something like this?</p>
  
  <pre><code>| ids | seq_num | names   |
  |-----|---------|---------|
  | 1   | 1       | sub_1_1 |
  | 3   | 2       | sub_2_1 |
  | 6   | 3       | sub_3_1 |
  </code></pre>
  
  <p>That is only pick the first row in a group.</p>