Comments (6)
@chelout That's awesome! Are you able to share a code example of that?
from laracon2018.
@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.
@fdalcin have a look https://stackoverflow.com/questions/20215744/how-to-create-a-mysql-hierarchical-recursive-query
from laracon2018.
If you use mysql 8, or postgres, you can do it with recursive cte.
from laracon2018.
@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.
@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)
- is possible to have feature requests file here? HOT 1
- Question on cutting down database queries for a recommended product
- More complex eager loading
- Error running database seeder HOT 4
- Eloquent scopes removed from subqueries HOT 1
- Fetching users that have events in a certain time interval
- Queued job fails when using subqueries with database driver HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laracon2018.