Question: I have table with child and parent hierarchy within same table.
I have column to identify the parent of the respective node.
Records like

```
Id  name  Parent
1    ABC   Null
2    PQR   1
3    DEF   Null
4    LMN   Null
5    OPQ   Null
6    JKL    2
7    TUY    4

CREATE TABLE #Temp
(
   Id INT,
   Name varchar(3),
   Parent INT
)

INSERT INTO #Temp VALUES (1,’ABC’,Null)
INSERT INTO #Temp VALUES (2,’PQR’, 1)
INSERT INTO #Temp VALUES (3,’DEF’, Null)
INSERT INTO #Temp VALUES (4,’LMN’, Null)
INSERT INTO #Temp VALUES (5,’OPQ’, Null)
INSERT INTO #Temp VALUES (6,’JKL’, 2)
INSERT INTO #Temp VALUES (7,’TUY’, 4)

```

How to write query to find out parent who have child and id of child?
More-over one query to find the the children who dont have parent ?

Answer: 
I've come across a few more tools,
but not really a documentation that can explain
all the internals.

I guess people dealing with Android internals
and the Android OS should have more ideas with
how to go about it.

This one (replaykit) works very well, although they don't expose the main source code just the binary files and documentation
<https://github.com/appetizerio/replaykit>
(and supports controlling multiple devices)

The one mentioned in another answer herem called RERUN (<http://www.androidreran.com/>) and the following one
 (which is bash oriented):  

<https://github.com/Cartucho/android-touch-record-replay>

Relay on pushing a compiled binary to your phone,
a command which allows to send the recorded events into the OS's
event stream.

Replay kit probably does it internally, or they have
another method.

If someone can give more info or tools, this would be great.
The RERAN tool is outdated and it needs root to record from a device and replay back **only** to this particular device with the particular Android version.

Check out appetizer-toolkit. It works with non-root devices with ADB debugging. And it can replay to devices with the same aspect ratio as the recording device.
<https://github.com/appetizerio/appetizer-toolkit>