Bottom Line Up Front: I am trying to find a way to format the output so that some data is left blank if it matches a preceding row.
I've edited as suggested by @philipxy because I really do want to learn how to write better code and write better questions to support that learning.
That being said, @ysth was able to solve my overly complex ask anyway. I changed the title and marked answered.
This is a sample table from my database:
(SELECT codename, dt_begin, id_alias FROM aliases GROUP BY codename;
)
+--------------+------------+----------+
| codename | dt_begin | id_alias |
+--------------+------------+----------+
| Arachniblade | 1999-12-23 | 1 |
| Arachniblade | 2016-07-04 | 2 |
| Beta | 2015-06-03 | 1 |
| Beta | 2016-07-04 | 3 |
| Cyberwolf | 2016-07-04 | 1 |
+--------------+------------+----------+
I would like the second (and any subsequent) instances of 'Arachniblade' and 'Beta' to be blank when ORDER BY codename
is used.
+--------------+------------+----------+
| codename | dt_begin | id_alias |
+--------------+------------+----------+
| Arachniblade | 1999-12-23 | 1 |
| | 2016-07-04 | 2 |
| Beta | 2015-06-03 | 1 |
| | 2016-07-04 | 3 |
| Cyberwolf | 2016-07-04 | 1 |
+--------------+------------+----------+
Similarly, if I ORDER BY id_alias
I would like to see only id 1 printed once but still retain all three records for 'Arachniblade,' 'Beta,' and 'Cyberwolf.'
+--------------+------------+----------+
| codename | dt_begin | id_alias |
+--------------+------------+----------+
| Arachniblade | 1999-12-23 | 1 |
| Beta | 2015-06-03 | |
| Cyberwolf | 2016-07-04 | |
| Arachniblade | 2016-07-04 | 2 |
| Beta | 2016-07-04 | 3 |
+--------------+------------+----------+
As @ysth mentioned LAG() is a part of the solution. I'm not sure how COALESCE fits in yet.