'Getting syntax error for WITH RECURSIVE (MySQL 8.0.27 version)

I keep getting a syntax error "WITH is not valid input in this position" for WITH RECURSIVE. I've seen a similar problem here, where people back in 2018 said MySQL will support CTE's in MySQL version 8. Some other sources also refer that CTE should work for MySQL since version 8.0. My current version is 8.0.27, however, I still can't use WITH RECURSIVE in MySQL Workbench.

The query I need to retrieve the family tree is:

  WITH RECURSIVE family_path (individual_id, first_name, path) AS
(
  SELECT individual_id, first_name, first_name as path
    FROM individual
    WHERE parent IS NULL
  UNION ALL
  SELECT c.individual_id, c.first_name, CONCAT(fp.path, ' > ', c.first_name)
    FROM family_path AS fp JOIN individual AS c
      ON fp.individual_id = c.parent
)
SELECT * FROM family_path
ORDER BY path;

Is there any way for me to solve this problem?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source