I have a parent and child table, I am able to retrieve all data using UNION SELECT.
id | parent_name 1 | Parent A 2 | Parent B
id | parent_id| child_name 1 | 1 | Child A 2 | 2 | Child B 3 | NULL | Child C
Using this query (http://sqlfiddle.com/#!9/f9f1c6/1)
Select parent.child_id, parent.parent_id, parent.child_name from Child c RIGHT JOIN ( Select NULL as child_id, parent.id as parent_id, parent_name as child_name from parent Union Select child.id as child_id, NULL as parent_id, child_name from Child ) parent on parent.parent_id = c.parent_id;
I get this result:
child_id| parent_id| name| NULL | 1 | Parent A | 1 | 1 | Child A | NULL | 2 | Parent B | 2 | 2 | Child B | 3 | NULL | Child C |
This is where I'm kinda lost. I want to retrieve a child that will still include the parent data.
WHERE ChildId = '1'; outside of join.
child_id| parent_id| name | NULL | 1 | Parent A | 1 | 1 | Child A |