Search
 
SCRIPT & CODE EXAMPLE
 

SQL

hierachichal sql query

WITH RECURSIVE employee_hierarchy AS (
  SELECT    employee_id,
            first_name,
            last_name,
            reports_to,
            'Owner' AS path
  FROM employee
  WHERE reports_to IS NULL
 
  UNION ALL
   
SELECT
    e.employee_id,
    e.first_name,
    e.last_name,
    e.reports_to,
    employee_hierarchy.path || '->' || e.last_name
  FROM employee e, employee_hierarchy
  WHERE e.reports_to = employee_hierarchy.employee_id
)
SELECT *
FROM employee_hierarchy;
Comment

PREVIOUS NEXT
Code Example
Sql :: setval postgres example table id 
Sql :: subconjuntos da linguagem SQL 
Sql :: mysql get last character of string 
Sql :: edit a field mysql terminal 
Sql :: get enginge db mysql 
Sql :: synapse sql table set pk 
Sql :: postgresql using reserved word as column name 
Sql :: mysql query to add hours to column in table 
Sql :: Fatal error: Uncaught mysqli_sql_exception: Unknown or incorrect time zone 
Sql :: oracle timestamp +1h 
Sql :: ring SQLite sqlite_execute 
Sql :: how to insert a ROWGUIDCOL into a table 
Sql :: ALV GRID events 
Sql :: mysql update sequence with order by 
Sql :: ltrim in sql 
Sql :: unable to open database database.db file is encrypted or is not a database 
Sql :: kill slow queries mysql 
Sql :: mysql c commands 
Sql :: grouping function in mysql 
Sql :: sql group by and having 
Sql :: Sql testing queries 
Sql :: strftime format sqlite 
Sql :: mysql join table with a text columns with ids splited by char 
Sql :: how to fetch unique records from two tables 
Sql :: coursera spark sql max count 
Sql :: visual c++ 2019 redistributable package mysql workbench 
Sql :: flask sqlalchemy single table inheritance 
Sql :: Limit in access query 
Sql :: sql redshift split into first and last name 
Sql :: sql grant select only 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =