I work in a ticketing system that exports data to a reporting DB using the company's version of SQL (similar to Postgre, though). I'm looking for a way to create a statement that pulls rows that are aggregates of related tickets. I've been having trouble searching StackOverflow or Google for this answer or anything similar.
Tickets can relate to each other in one direction. If ticket A is linked to the newly created ticket B, a row appears in a related items table as
First ticket Second ticket
------------ -------------
Ticket A Ticket B
Sometimes ticket B will get related to ticket C and ticket C is related to ticket D and so on and so on.
First ticket Second ticket
------------ -------------
Ticket A Ticket B
Ticket B Ticket C
Ticket C Ticket D
Ticket D Ticket E
Ticket E Ticket F
I can see that tickets A, B, C, D, E, and F are related but I don't know how to pull that data to show that. I want to look at a string of all related tickets and determine statistics on this chain. I've tried to self-join on this table 5 times but what if the relation goes 6, 7 or n tickets deep?
I suppose what I would want is a statement that could look at any ticket in this related chain and produce a row that looks like
Ticket A, Ticket B, Ticket C, Ticket D, Ticket E, Ticket F
Thanks