I would like to check if child rows exist 3 levels down, 2 levels down and 1 level down.
select max(
case
(select row from category where relatedRow in (select row from category where relatedRow=?)) is not null then 3
(select row from category where relatedRow=?) is not null then 2
(select row from category where row=?) is not null then 1
else 0 end
) as level from category
How can I make this work?
This query goes as follows. If there are rows that have related rows of the related rows (grandchildren), level=3. If there are related rows (children), level 2. If there is a row=? (parent), level 1. If there is no parent (ghost), level 0.