I am having problem in framing one sql query.
I need to select all records based on Transaction ID as I explained below
- Assume user given transaction TX444, I need to fetch all records with Child Id = Parent Id of given transaction AND Parent_Id = Child_Id of already selected records.
So if I give TRansaction as TX444, all records shown should be selected.
- Assume user given Transaction = TX234, then I need to fetch all records with Child Id = Parent Id of given transaction AND Parent_Id = Child_Id of already selected records.
in this case last record will not be included.
I am trying to write SELECT query. But nothing is working 🙁
PARENT_ID CHILD_ID TRANSACTION STATE
1 4 TX123 PF
2 4 TX128 PS
3 5 TX230 FF
4 5 TX234 FS
5 0 TX444 DS
I am not SQL person, but I need to make this up
In Oracle you can use CONNECT BY to recursively loop through rows:
I’ve put an example on SQL Fiddle, but I’ve used slightly different children/parents to your data to fully show how you can use
CONNECT BYnot just to get the parents/children, but also to determine what generation each is.