Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle SQL hiding duplicate values

I have a query with these results:

A | 1
A | 2
B | 1
B | 2
B | 3

How do I get the results to be like this:

A | 1
  | 2  
B | 1   
  | 2   
  | 3
like image 283
Michael Avatar asked Nov 18 '25 14:11

Michael


1 Answers

Here is one way:

SELECT CASE WHEN rn = 1 THEN c1 ELSE NULL END || ' | ' || c2
  FROM (SELECT c1, c2, ROW_NUMBER() OVER (PARTITION BY c1 ORDER BY c2) rn
          FROM your_table);
like image 82
DCookie Avatar answered Nov 20 '25 05:11

DCookie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!