Let say we have this table:
+─────+────────────+───────+
| id | parent_id | code |
+─────+────────────+───────+
| 1 | | A |
| 2 | 1 | |
| 3 | 1 | |
| 4 | | B |
+─────+────────────+───────+
I need to search for records that have code "A" and those which their parent have code "A" as well. In this case, the query result should return records with id: 1, 2 and 3.
Why those 3?
id 1: has code "A".
id 2: its parent 1 has code "A".
id 3: its parent 1 has code "A".
Any idea will be really appreciated. Thanks.