Giter Club home page Giter Club logo

Comments (6)

reinink avatar reinink commented on July 28, 2024 1

@chelout That's awesome! Are you able to share a code example of that?

from laracon2018.

chelout avatar chelout commented on July 28, 2024 1

@reinink yeah, that's gonna be like this on mysql 8:

with recursive subordinates AS (
    select id, employee_id, name from employees where id = 1
    union all
    select employees.id, employees.employee_id, employees.name from employees
		inner join subordinates on subordinates.id = employees.employee_id
)
select * from subordinates;

from laracon2018.

chelout avatar chelout commented on July 28, 2024 1

@fdalcin have a look https://stackoverflow.com/questions/20215744/how-to-create-a-mysql-hierarchical-recursive-query

from laracon2018.

chelout avatar chelout commented on July 28, 2024

If you use mysql 8, or postgres, you can do it with recursive cte.

from laracon2018.

fdalcin avatar fdalcin commented on July 28, 2024

@chelout yeah, that would be the best solution.
Unfortunately MariaDB only supports that on 10.2 and I am not able to migrate at the moment.

Is there another way with a lower version?

Just one question about that solution, do I need to run the WITH RECURSIVE everytime? Or will it create some sort of table?

from laracon2018.

fdalcin avatar fdalcin commented on July 28, 2024

@chelout It seems to me that this approach will work as expected:

select id, employee_id, name
from (select * from employees order by employee_id, id) employee_list,
     (select @pv := 1) filter
where find_in_set(employee_id, @pv)
and length(@pv := concat(@pv, ',', id))

Thanks for your help

from laracon2018.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.