Let's say I have the following table:
ID | parentID | MoreStuff
1 | -1 | ...
2 | 1 | ...
3 | 1 | ...
4 | 2 | ...
5 | 1 | ...
How can I generate a SQL SELECT statement to find out if a particular row has children? In other words, I want to know if ID 1 has children, which in this case have 3.
I am not sure how to create an SQL statement:
SELECT ID, hasChildren FROM myTable;
What will be replaced with hasChildren in the SQL SELECT statement above?
source
share