clear markdown compare help best fiddles feedback dbanow.uk
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 2555375 fiddles created (37444 in the last week).

CREATE TABLE employees ( employee_id serial PRIMARY KEY, full_name VARCHAR NOT NULL, manager_id INT, age INT NOT NULL );
 hidden batch(es)


INSERT INTO employees ( employee_id, full_name, manager_id, age ) VALUES (1, 'Michael North', NULL, 24), (2, 'Megan Berry', 1, 20), (3, 'Sarah Berry', 1, 31), (4, 'Zoe Black', 1, 25), (5, 'Tim James', 1, 33), (6, 'Bella Tucker', 2, 22), (7, 'Ryan Metcalfe', 2, 19), (8, 'Max Mills', 2, 36), (9, 'Benjamin Glover', 2, 33), (10, 'Carolyn Henderson', 3, 40), (11, 'Nicola Kelly', 3, 27), (12, 'Alexandra Climo', 3, 21), (13, 'Dominic King', 3, 44), (14, 'Leonard Gray', 4, 25), (15, 'Eric Rampling', 4, 36), (16, 'Piers Paige', 7, 30), (17, 'Ryan Henderson', 7, 20), (18, 'Frank Tucker', 8, 35), (19, 'Nathan Ferguson', 8, 49), (20, 'Kevin Rampling', 8, 50)
20 rows affected
 hidden batch(es)


WITH RECURSIVE subordinates AS ( SELECT employee_id, manager_id FROM employees WHERE employee_id = 2 UNION SELECT e.employee_id, e.manager_id FROM employees e INNER JOIN subordinates s ON s.employee_id = e.manager_id WHERE e.age >= 30 ) SELECT e.full_name FROM subordinates INNER JOIN employees AS e ON e.employee_id = subordinates.employee_id;
full_name
Megan Berry
Max Mills
Benjamin Glover
Frank Tucker
Nathan Ferguson
Kevin Rampling
 hidden batch(es)