I have one table with multiple rows where some rows are the other's "children".
The table looks like this:
id, name, parent, slug
Sample data:
1, Jack, NULL, jack
2, John, NULL, john
3, Mike, jack, mike
The query should return jack, because it's mike's parent.
so I want to return the rows that are specified in other rows as "parents". I'm really new to MySQL and I have no idea how to do it.
Unfortunately I didn't get lucky with Google too because I'm not sure how to ask exactly.
Thanks!
idfield, not thename.Parentactually referencing thenamefield, as you've defined, or is it actually referencing theidfield? If it's using theNamefield, you will definitely want to consider refactoring this table.IDfor the parent reference. That's the identifying field for the record. Consider: what would happen if there were two people namedJack?