I have a little bit complicated query.
I have table
tbl_Categories {CategoryID, Name, CategoryId_fk}
and it it a self referenced table.
When CategoryId_fk is NULL then that row is parent when there is a value that it is a child.
I have problem to select all children (it's where CategoryId_fk is not null) and rows where CategoryId_fk is null and doesn't have children.
I tried something but doesn't work:
SELECT a.*
FROM tbl_Categories a
WHERE NOT EXISTS (
SELECT 1 FROM tbl_Categories b
WHERE b.CategoryId_fk= a.CategoryId_fk
)