Difference between a CROSS JOIN and a Cartesian product of the noted comma?
Hello everyone,Oracle version: Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit
OS: Linux Fedora Core 17 (x86_64)
I was practicing on recursive subquery factoring based on oracle examples available in the documentation
http://docs.Oracle.com/CD/E11882_01/server.112/e26088/statements_10002.htm#i2129904
I was working on an example that displays the hierarchy of each manager with related employees. Here's how
WITH tmptab(empId, mgrId, lvl) AS
(
SELECT employee_id, manager_id, 0 lvl
FROM employees
WHERE manager_id IS NULL
UNION ALL
SELECT employee_id, manager_id, lvl+1
FROM employees, tmptab
WHERE (manager_id = empId)
)
SEARCH DEPTH FIRST BY mgrId SET order1
SELECT LPAD(' ', lvl * 3, ' ') || empId AS empId
FROM tmptab;
Which gives the desired resultEMPID
---------------------
100
101
108
109
110
111
112
113
200
203
204
205
206
102
103
104
105
106
107
114
115
116
117
118
119
120
125
126
127
128
180
181
182
183
121
129
130
131
132
184
185
186
187
122
133
134
135
136
188
189
190
191
123
137
138
139
140
192
193
194
195
124
141
142
143
144
196
197
198
199
145
150
151
152
153
154
155
146
156
157
158
159
160
161
147
162
163
164
165
166
167
148
168
169
170
171
172
173
149
174
175
176
177
178
179
201
202
107 rows selected.
SQL>
However, by chance, I noticed that if I put CROSS JOIN instead of put a comma between table names, the same query behaves differently.In other words, if instead of writing
. . .
UNION ALL
SELECT employee_id, manager_id, lvl+1
FROM employees, tmptab
WHERE (manager_id = empId)
I am writing. . .
UNION ALL
SELECT employee_id, manager_id, lvl+1
FROM employees CROSS JOIN tmptab
WHERE (manager_id = empId)
I get the following error messageERROR at line 4:
ORA-32044: cycle detected while executing recursive WITH query
Any idea?Correct me if I'm wrong, but I remember, oracle supports as many JOIN CROSSROADS notation for Cartesian product (vector product =). For example
SQL> WITH tmptab1 AS
2 (
3 SELECT 'a1' AS colval FROM DUAL UNION ALL
4 SELECT 'a2' AS colval FROM DUAL UNION ALL
5 SELECT 'a3' AS colval FROM DUAL
6 ),
7 tmptab2 AS
8 (
9 SELECT 'b1' AS colval FROM DUAL UNION ALL
10 SELECT 'b2' AS colval FROM DUAL
11 )
12 SELECT t1.colval, t2.colval
13 FROM tmptab1 t1 CROSS JOIN tmptab2 t2;
CO CO
-- --
a1 b1
a2 b1
a3 b1
a1 b2
a2 b2
a3 b2
6 rows selected.
SQL> LIST 13
13* FROM tmptab1 t1 CROSS JOIN tmptab2 t2
SQL>
SQL>
SQL> CHANGE /CROSS JOIN/,
13* FROM tmptab1 t1 , tmptab2 t2
SQL>
SQL>
SQL> LIST
1 WITH tmptab1 AS
2 (
3 SELECT 'a1' AS colval FROM DUAL UNION ALL
4 SELECT 'a2' AS colval FROM DUAL UNION ALL
5 SELECT 'a3' AS colval FROM DUAL
6 ),
7 tmptab2 AS
8 (
9 SELECT 'b1' AS colval FROM DUAL UNION ALL
10 SELECT 'b2' AS colval FROM DUAL
11 )
12 SELECT t1.colval, t2.colval
13* FROM tmptab1 t1 , tmptab2 t2
SQL>
SQL> /
CO CO
-- --
a1 b1
a2 b1
a3 b1
a1 b2
a2 b2
a3 b2
6 rows selected.
SQL>
So if the two rated commas and CROSS JOIN have the same semantics, why do I get a cycle mentioned above cites recursive subquery factoring while the same query works pretty well with comma between table instead of CROSS JOIN names? Because if a cycle is detected (= current element ancestor) it means that the product with the CROSS JOIN notation produces duplicates which are absent in the result of the Cartesian product rated comma.I would appreciate it if you could kindly shed some light.
Thanks in advance,
Kind regards
Dariyoosh
Hello
dariyoosh wrote:
... Oracle terminology could become really confusing. But once again, according to the online glossary, a Cartesian product is apparently regarded as a join
http://docs.Oracle.com/CD/E11882_01/server.112/e25789/glossary.htm?type=popup#CNCPT44493
>
There is no doubt that a Cartesian product (also called cross join) is a join. If loops in a WITH recursive clause are detected after completing the joins, but before other conditions apply, the relevant question here is "what are the requirements to join?
In the ANSI syntax, the distinction is always clear. Join conditions occur in the... Clause WE
SELECT employee_id, manager_id, lvl + 1
FROM employees
JOIN tmptab ON (manager_id = empId) -- Join condition
;
and other conditions occur in the WHERE (or HAVING or CONNECT BY) clause.
SELECT employee_id, manager_id, lvl + 1
FROM employees
CROSS JOIN tmptab
WHERE (manager_id = empId) -- NOT a join condition
;
In the joins of the former, it seems to be the case that any condition involving 2 or more tables (or the + indicator of outer join) is a condtion of join:
SELECT employee_id, manager_id, lvl + 1
FROM employees
, tmptab
WHERE (manager_id = empId) -- Join condition
;
Tags: Database
Similar Questions
-
Difference between ISO ESXi M420 and M630. Is this the same ISO?
I will install 6.0 ESXi update 2 of 3 new servers M630. I used the ISO next to install my m420s:
VMware-VMvisor-Installer-6.0.0.update02-3620759.x86_64-Dell_Customized-A02.iso
This ISO works for my m630s so?
These aircraft were ordered and received by a dealer, and they don't did me not service tags. This is why I can not add to my products and see the available downloads. This can become a common problem for me because I am in charge of the deployment. Thank you in advance for the answer to my question.
Yes, it's the same file. The two show under systems supported and same hash.
-
Difference between Esx v 2 and 3 and ESX 2.5 and 3.5
Hello
I want to know the differences between ESX V.2 and 3 and ESX 2.5 and 3.5. can someone help me on respect.
Karthik.
Hello
The biggest difference between ESX 2.x and 3.x is how the virtualization of the boots as well as configurations of network virtual host.
In ESX 2.x booted Linux then VMware took control.
In ESX 3.x VMware started then place the unit of management within a virtual machine started.
ESXi boots the vmkernel then starts a Posix environment in the vmkernel.
The book of VMware ESX Server in the enterprise passes over these differences in a bit of detail, if you are interested.
Best regards
Edward L. Haletky VMware communities user moderator, VMware vExpert 2009, url = http://www.virtualizationpractice.comvirtualization practical analyst [url]
"Now available: url = http://www.astroarch.com/wiki/index.php/VMware_Virtual_Infrastructure_Security' VMware vSphere (TM) and Virtual Infrastructure Security: securing the virtual environment ' [url]
Also available url = http://www.astroarch.com/wiki/index.php/VMWare_ESX_Server_in_the_Enterprise"VMWare ESX Server in the enterprise" [url]
[url =http://www.astroarch.com/wiki/index.php/Blog_Roll] SearchVMware Pro [url] | URL = http://www.astroarch.com/blog Blue Gears [url] | URL = http://www.astroarch.com/wiki/index.php/Top_Virtualization_Security_Links Top security virtualization [url] links | URL = http://www.astroarch.com/wiki/index.php/Virtualization_Security_Round_Table_Podcast Virtualization Security Table round Podcast [url] -
Difference between nio-file manager and nio-memory-manager
Hello
What is the difference between nio-file manager and memory manager Ian? The documentation is not really discuss the differences as far as I know. They all use two nio to store files mapped into memory Don't they? What are the advantages/disadvantages of both?
When to choose the first and when the second during the storage of a large amount of data? Can be used to query data with the filter API? Are there any size limits on both?
Best regards
JanHi Jan,
The difference is that one uses a memory-mapped file and used memory direct nio (as part of the memory allocated by the JVM process) to store data. Both allow data cached out-of-heap storage, which can store more data with a knot of unique cache (FMV) without long GC pauses.
If you use a 32-bit JAVA virtual machine, JVM process will be limited to a total of ~ 3 on Windows and 4 GB on Linux/Solaris. This includes lots and out of the stack of memory allocation.Regarding the size of the limitations for the Manager of files-Ian, please see the doc the following for more information.
With version 3.5, now is the idea of a Partitioned card support that allows to create more large (up to 8 GB of capacity) for storage of nio. Please refer to the following, doc.Both can be used to query the data, but it is worth noting that the index will be stored in the heap.
HTH,
-Dave -
What is the difference between Ubuntu desktop edition and server edition?
What is the difference between ubuntu desktop edition and server edition?
Desktop Gets the window manager and terminal server :)
-
Difference between Satellite Pro L300 and Pro A300
Can someone please tell me the difference between Pro A300-21F and Pro L300-1RS as specifications on Tosh pages seem to be identical.
Like us all, I'm looking for the more powerful machine at the lowest cost. TKS
_Satellite pro A300-21F: _
-Intel (r) Pentium (r) Dual Core processor T3400
-SATA 160 GB (5400 RPM)
-Chip graphics Mobile INTEL GL40
-2 GB DDR2 (800 MHZ)
-No Bluetooth
-No fingerprint sensor_Satellite pro L300-1RS_
-Intel (r) Pentium (r) Dual Core T3200 or Intel (r) Pentium (r) Dual Core processor T3400
-SATA 160 GB (5400 RPM)
-Chip graphics Mobile INTEL GL40
-No Bluetooth
-No fingerprint sensor
-TV out (composite) or RGB external monitor available routesYou are right, the two models of notebooks seems to be very similar and supports virtually the same devices.
Good bye
-
Difference between DAQmx DAQmx Base and acquisition of Legacy data
Hello
What is the difference between NI-DAQmx, DAQmxBase and acquisition of data Legacy and what are the characteristics of these materials
See this FAQ.
And it's the software, not hardware.
-
I want to create a simulation of 3D on the front panel, and I see that we can use a 3D image control or a display of Simulator control. It seems that each of them can be used at the same position. What is the most important difference between 3D Picture control and display of Simulator?
Hi sfh1,
You are right, I found examples of Robotics that use 3D photo control and display Simulator control to display a scene 3D on the front panel. After further research, it seems that control the display of Simulator adds additional features compared to the 3D picture control. The control displays Simulator allows the user to right-click control during execution and change the background color, draw fashion, draw contact, view the ID of robot, display sensor data, suspension of service Simulator and reset service Simulator.
More in depth on these options and the display of control Simulator can be found here:
http://zone.NI.com/reference/en-XX/help/372983D-01/lvrobogsm/robo_controls_concepts/
If you would like more information on the picture here 3D control is another resource:
http://www.NI.com/white-paper/3170/en/#toc2
Kind regards
-
What is the difference between HP Photo Creations and Snapfish
I've been curious.
What is the difference between HP Photo Creations and Snapfish?
Hi Jeff17866. The difference between these two services are the location, accessibility and share-ability of the recorded images. Snapfish is a photo on the web edition and sharing and belonged to printing HP service. You upload your images on the Snapfish site and share with other sites (Facebook, Flickr, etc) by selecting the appropriate options. The images are then stored on the cloud, and you will be able to access it from any device with Internet access. So, if you want to easily share your photos with your friends and family around the country, Snapfish is a great tool to do. HP Photo Creations is a photo editing software that you download to your desktop. You can edit your photos and order prints just as with Snapfish, but all pictures remain on your hard drive. They can be shared by downloading files on the sites you want the images appear, but you are not able to access it on other devices. -Chauntain
-
HOW smart card smart card slots look like? What are the differences between smart card slots and cards express?
Hi Smitty,
Yes, so ExpressCard is an interface that has a USB port to this topic where I can plug in external devices to be attached to my computer right? I did a search on google but could not find photo Card Slot smart. I need a picture to get an idea of how look like a smart card Slot.
Next time try BING...
http://tinyurl.com/95rgwxw
http://tinyurl.com/9plc7ztScroll to the left view (image 5)
http://support.Dell.com/support/eDOCS/systems/latd610/en/ug_en/about.htm
-
What is the difference between windows 2000, XP and Windows 7
Hi please God let me know the difference between windows 2000, xp and win 7. I want t o knopw technical specification.
Thank you
JAI
You can find many differences between older and newer Windows versions. Windows is always improving with better technology. Visit this link for the versions to compare Microsoft Windows:
You can also see this article on the Microsoft Windows Web site: -
What is the difference between Windows XP Mode and Windows XP Mode "N".
It's confusing. Why are there two downloads of Windows XP Mode? And what is the difference between XP normal Mode and XP Mode "N"?
Thank you for your response.
The "n" of Windows versions contain no Windows Media Player. It is the result of an agreement with the European Commission to settle the dispute of the competition.
-
What is the difference between manual (startup type) and started (status)
What is the difference between manual (startup type) and started (status)
If I set the automatic startup type and the State stopped, what will happen?
It starts automatically at startup, but will not start?
Hi zkteh,
Please see article with some information:
I hope this helps!
-
What is the difference between Adobe Reader XI and Adobe Fine Reader?
What is the difference between Adobe Reader XI and Adobe Reader.Do Fine they do the same work or accomplish different tasks?
Hiddon icons simply shows a software that has been installed on your PC and is set to auto run at startup
I've included this info I thought you were trying to asertain what programs may have been installed on your PC and were running in the background.
-
What is the difference between full Windows 7 and Windows 7 license generator system?
The Windows 7 System Builder license cost about $100.00 and the full Windows 7 on $190.00.
I am upgrading to Windows Vista 64 for Windows 7 64. It is true that I will lose everything on my drive hard because I'll need to do a clean install?
See this thread:
Maybe you are looking for
-
Untrusted sites Firefox 31.0 (OSX) with the certificates don't is not loading
As mentioned above, since the update to 31.0 (resettlement 30.0 fixed the problem), I am unable to access new sites with untrusted certificates. I don't get even the option to trust/continue the site simply crashes and never loads. Any suggestions on
-
Hi, I would like to know if is better to stop a macbook pro or left in sleep, when doing small journeys, from home to studio for example or to let in mode 'sleep'... Thank you
-
Installation of Windows XP on Satellite P200D-106
Hello! some application that I use Don t support windows vista so I decided to install xp and I understand that I don't have drivers for xp. Is - any way to get it?
-
HP 15-ac169tu: how to install windows 10 in the BACK
I got this laptop (Hp 15-ac169tu) in line with freeDos and I want to install Windows 10. I choose custom installation & there are already two partition created by manufacturer that is to say, 1 & 2 with 7.8 GB each and 915,9 GB partition is not used.
-
How to block or remove the account from the previous owner of PC refurbished?
I get emails via Outlook Express that are sent to the previous owner of my PC refurbished. I don't know how it happens. I don't use Outlook Express so am not familiar with it. I thought that I deleted the account, but email keeps coming back and tak