sql - Duplicate table in Oracle query -


i have query looks this:

select *   employees e,   departments d1,   departments d2,   departments d3,   departments d4 e.dep1 = d1.dep(+) , e.dep2 = d2.dep(+) , e.dep3 = d3.dep(+) , e.dep4 = d4.dep(+); 

is there better way write don't need use same table in query multiple times? know oracle's optimizer works around rather nicely, if there more efficient way write query this, i'm ears. keep in mind above merely example, actual query has lot more going on in it. i'm using oracle 11.2.0.3 on windows 2003 x64.

thanks, tom

this valid.

the contrived example me , colleague use city_of_birth , city_of_residence. let's assume want query employees live in different country born in (and countries have states).

you query follows:

select e.* employees e,      cities city_of_birth,      cities city_of_residence,      states state_of_birth,      states state_of_residence e.city_of_birth_id = city_of_birth.id   , e.city_of_residence_id = city_of_residence.id   , city_of_birth.state_id = state_of_birth.id   , city_of_residence.state_id = state_of_residence.id   , state_of_birth.country_id != state_of_residence.country_id; 

the thing note tables need referenced in from clause of query there different meanings them.

another way think it: need reference same table multiple times in from clause if you're going selecting different rows each "instance".


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -