dbTalk Databases Forums  

Self Join on Subquery

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss Self Join on Subquery in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Hans Mayr
 
Posts: n/a

Default Self Join on Subquery - 02-21-2008 , 07:32 AM






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

Reply With Quote
  #2  
Old   
Michael O'Shea
 
Posts: n/a

Default Re: Self Join on Subquery - 02-21-2008 , 07:38 AM






On Feb 21, 1:32*pm, Hans Mayr <mayr1... (AT) gmx (DOT) de> wrote:
Quote:
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

http://www.psoug.org/reference/with.html



Regards

TESSELLA Michael.OShea (AT) tessella (DOT) com
__/__/__/ Tessella Support Services plc
__/__/__/ 3 Vineyard Chambers, ABINGDON, OX14 3PX, England
__/__/__/ Tel: (44)(0)1235-555511 Fax: (44)(0)1235-553301
www.tessella.com Registered in England No. 1466429





Reply With Quote
  #3  
Old   
Michael O'Shea
 
Posts: n/a

Default Re: Self Join on Subquery - 02-21-2008 , 07:38 AM



On Feb 21, 1:32*pm, Hans Mayr <mayr1... (AT) gmx (DOT) de> wrote:
Quote:
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

http://www.psoug.org/reference/with.html



Regards

TESSELLA Michael.OShea (AT) tessella (DOT) com
__/__/__/ Tessella Support Services plc
__/__/__/ 3 Vineyard Chambers, ABINGDON, OX14 3PX, England
__/__/__/ Tel: (44)(0)1235-555511 Fax: (44)(0)1235-553301
www.tessella.com Registered in England No. 1466429





Reply With Quote
  #4  
Old   
Michael O'Shea
 
Posts: n/a

Default Re: Self Join on Subquery - 02-21-2008 , 07:38 AM



On Feb 21, 1:32*pm, Hans Mayr <mayr1... (AT) gmx (DOT) de> wrote:
Quote:
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

http://www.psoug.org/reference/with.html



Regards

TESSELLA Michael.OShea (AT) tessella (DOT) com
__/__/__/ Tessella Support Services plc
__/__/__/ 3 Vineyard Chambers, ABINGDON, OX14 3PX, England
__/__/__/ Tel: (44)(0)1235-555511 Fax: (44)(0)1235-553301
www.tessella.com Registered in England No. 1466429





Reply With Quote
  #5  
Old   
Michael O'Shea
 
Posts: n/a

Default Re: Self Join on Subquery - 02-21-2008 , 07:38 AM



On Feb 21, 1:32*pm, Hans Mayr <mayr1... (AT) gmx (DOT) de> wrote:
Quote:
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

http://www.psoug.org/reference/with.html



Regards

TESSELLA Michael.OShea (AT) tessella (DOT) com
__/__/__/ Tessella Support Services plc
__/__/__/ 3 Vineyard Chambers, ABINGDON, OX14 3PX, England
__/__/__/ Tel: (44)(0)1235-555511 Fax: (44)(0)1235-553301
www.tessella.com Registered in England No. 1466429





Reply With Quote
  #6  
Old   
Hans Mayr
 
Posts: n/a

Default Re: Self Join on Subquery - 02-21-2008 , 08:31 AM



Thanks! Wonderful!

Hans

Reply With Quote
  #7  
Old   
Hans Mayr
 
Posts: n/a

Default Re: Self Join on Subquery - 02-21-2008 , 08:31 AM



Thanks! Wonderful!

Hans

Reply With Quote
  #8  
Old   
Hans Mayr
 
Posts: n/a

Default Re: Self Join on Subquery - 02-21-2008 , 08:31 AM



Thanks! Wonderful!

Hans

Reply With Quote
  #9  
Old   
Hans Mayr
 
Posts: n/a

Default Re: Self Join on Subquery - 02-21-2008 , 08:31 AM



Thanks! Wonderful!

Hans

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.