I need to search title '%p%'. if i check title ,parent tile and status as parent and child level. if the searched title parent visible is true then show the child Title.
CREATE TABLE CTE(
Title VARCHAR(20),
ParentTitle VARCHAR(20),
visible VARCHAR(20),
)
INSERT INTO CTE
VALUES
('p1', 'Home', 'TRUE'),
('p1.1', 'p1', 'TRUE'),
('p1.2', 'p1', 'FALSE'),
('p1.3', 'p1.2', 'TRUE'),
('p1.3.1', 'p1.3', 'TRUE'),
('p2', 'Home', 'TRUE'),
('p2.1', 'p2', 'TRUE'),
('p2.2', 'p2.1', 'FALSE'),
('P3', 'Home', 'TRUE'),
('p3.1', 'p3', 'TRUE'),
('P3.1.1', 'p3.1', 'FALSE')
I need output like
title
p1
p1.1
p2
p2.1
P3
p3.1
What I have tried:
Select b.Title,b.ParentTitle from CTE B
left join CTE C ON C.ParentTitle=b.Title AND b.visible='TRue'
where b.ParentTitle in(Select a.ParentTitle from CTE A join CTE B on a.Title=b.ParentTitle and b.visible='false')
i tried this query. But i can't get correct answer..