![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hello, This is the standard example for self joins: SELECT e.last_name employee, m.last_name manager * FROM employees e INNER JOIN employees m * * * *ON e.manager_id = m.employee_id; Now imagine that I want to do a self join not on a table but on a complicated subquery: SELECT e.last_name employee, m.last_name manager * FROM (SELECT ... complicated subquery ...) e INNER JOIN (SELECT ... identical complicated subquery ...) m * * * *ON e.manager_id = m.employee_id; I do not like the fact that I repeat the same "complicated subquery" code twice in my query. Is there a possibility to do the same thing without including the code of the subquery twice? This would save time, avoid errors and would probably be faster. Thanks. Hans |
#3
| |||
| |||
|
|
Hello, This is the standard example for self joins: SELECT e.last_name employee, m.last_name manager * FROM employees e INNER JOIN employees m * * * *ON e.manager_id = m.employee_id; Now imagine that I want to do a self join not on a table but on a complicated subquery: SELECT e.last_name employee, m.last_name manager * FROM (SELECT ... complicated subquery ...) e INNER JOIN (SELECT ... identical complicated subquery ...) m * * * *ON e.manager_id = m.employee_id; I do not like the fact that I repeat the same "complicated subquery" code twice in my query. Is there a possibility to do the same thing without including the code of the subquery twice? This would save time, avoid errors and would probably be faster. Thanks. Hans |
#4
| |||
| |||
|
|
Hello, This is the standard example for self joins: SELECT e.last_name employee, m.last_name manager * FROM employees e INNER JOIN employees m * * * *ON e.manager_id = m.employee_id; Now imagine that I want to do a self join not on a table but on a complicated subquery: SELECT e.last_name employee, m.last_name manager * FROM (SELECT ... complicated subquery ...) e INNER JOIN (SELECT ... identical complicated subquery ...) m * * * *ON e.manager_id = m.employee_id; I do not like the fact that I repeat the same "complicated subquery" code twice in my query. Is there a possibility to do the same thing without including the code of the subquery twice? This would save time, avoid errors and would probably be faster. Thanks. Hans |
#5
| |||
| |||
|
|
Hello, This is the standard example for self joins: SELECT e.last_name employee, m.last_name manager * FROM employees e INNER JOIN employees m * * * *ON e.manager_id = m.employee_id; Now imagine that I want to do a self join not on a table but on a complicated subquery: SELECT e.last_name employee, m.last_name manager * FROM (SELECT ... complicated subquery ...) e INNER JOIN (SELECT ... identical complicated subquery ...) m * * * *ON e.manager_id = m.employee_id; I do not like the fact that I repeat the same "complicated subquery" code twice in my query. Is there a possibility to do the same thing without including the code of the subquery twice? This would save time, avoid errors and would probably be faster. Thanks. Hans |
#6
| |||
| |||
|
#7
| |||
| |||
|
#8
| |||
| |||
|
#9
| |||
| |||
|
![]() |
| Thread Tools | |
| Display Modes | |
| |