OCA Oracle Database 11gCAP-6<br />SQL FUNDAMENTALS I<br />Datos de Multiples<br />Tablas<br />
Para realmente ver todo el potencial de SQL es necesario utilizar multiples tablas.<br />Una consulta en SQL es mucho mas ...
Select * fromcountrieswherecontry_id=‘CA’;<br />Selectregion_namefromregionswhereregion_id=‘2’;<br />
Combinacion Natural<br />Se implementa utilizando tres clausulas en diferentes combinaciones:<br />Natural Join<br />Using...
Selectregion_namefromregions natural joincountrieswherecountry_name= ‘Americas’<br />Selectregion_namefromregionsjoincount...
Cross Join<br />O producto cartesiano, produce una relación en la que cada tupla de la primera tabla se combina con todas ...
Selectcount(*) fromcountries;<br />Selectcount(*) fromregions;<br />Selectcount(*) fromregionscrossjoincountries;<br />
Selectr.regions_name, c.country_namefromregions r, countries c wherer.region_id=c.region_id<br />Selectlast_name, departme...
Clausula NATURAL JOIN<br />SELECT tabla1.column, tabla2.column<br />FROM tabla1<br />NATURAL JOIN tabla2<br />
Select * fromlocations natural joincountries;<br />Select * fromlocations, countrieswherelocations.country_id= countries.c...
Clausula JOIN USING<br />SELECT tabla1.colum1, tabla2.colum2<br />FROM tabla1<br />JOIN tabla2 USING (JoinColum1, JoinColu...
Select * fromlocations, countrieswherelocations.country_id = countries.country_id ;<br />Select * fromjobsjoincountriesusi...
Select * fromdepartments d joinemployees e on (e.employee_id = d.department_id)<br />Select * fromemployees e, departments...
Ejercicio<br />Muestre un listado de todos los Gerentes de departamento, liste el nombre el apellido y el nombre del depar...
Select * from Tabla1 natural join Tabla2 using (column1)<br />Recuerde que USING, ON, y NATURAL son mutuamente excluyentes...
LeftOuter<br />Selecte.employee_id, e.department_id, d.department_id, d.department_namefromdepartments d LEFT OUTER JOIN e...
Rightouterjoin<br />Selecte.last_name, d.department_namefromdepartments d rightouterjoinemployees e on (e.department_id = ...
Producto cartesiano<br />Select * fromjobscrossjoinjob_history;<br />Select * fromjobs j crossjoinjob_historyjhwherej.job_...
Quien hace lo que le apasiona nunca tendrá trabajo, tendrá diversión<br />
Upcoming SlideShare
Loading in …5
×

Cap 7. oracle SQL fundamentals

3,661 views

Published on

Published in: News & Politics
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,661
On SlideShare
0
From Embeds
0
Number of Embeds
641
Actions
Shares
0
Downloads
142
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Cap 7. oracle SQL fundamentals

  1. 1. OCA Oracle Database 11gCAP-6<br />SQL FUNDAMENTALS I<br />Datos de Multiples<br />Tablas<br />
  2. 2. Para realmente ver todo el potencial de SQL es necesario utilizar multiples tablas.<br />Una consulta en SQL es mucho mas potente que un proceso iterativo.<br />
  3. 3.
  4. 4. Select * fromcountrieswherecontry_id=‘CA’;<br />Selectregion_namefromregionswhereregion_id=‘2’;<br />
  5. 5. Combinacion Natural<br />Se implementa utilizando tres clausulas en diferentes combinaciones:<br />Natural Join<br />Using<br />On<br />Cuando la tabla padre e hija tienen columnas idénticas es posible realizar la combinación natural<br />
  6. 6. Selectregion_namefromregions natural joincountrieswherecountry_name= ‘Americas’<br />Selectregion_namefromregionsjoincountriesusing (region_id) wherecountry_name=‘Canada’<br />Selectcountry_namefromcountriesjoinregionson (countries.region_id = regions.region_id) whereregion_name=‘America’<br />
  7. 7. Cross Join<br />O producto cartesiano, produce una relación en la que cada tupla de la primera tabla se combina con todas las tuplas de la segunda tabla.<br />
  8. 8. Selectcount(*) fromcountries;<br />Selectcount(*) fromregions;<br />Selectcount(*) fromregionscrossjoincountries;<br />
  9. 9. Selectr.regions_name, c.country_namefromregions r, countries c wherer.region_id=c.region_id<br />Selectlast_name, department_namefromemployees, departmentswhereemployees.department_id=departments.department_id;<br />Select * fromregions, countries;<br />
  10. 10. Clausula NATURAL JOIN<br />SELECT tabla1.column, tabla2.column<br />FROM tabla1<br />NATURAL JOIN tabla2<br />
  11. 11. Select * fromlocations natural joincountries;<br />Select * fromlocations, countrieswherelocations.country_id= countries.country_id;<br />Select * fromjobs natural joincountries;<br />Select * fromjobs, countries;<br />
  12. 12. Clausula JOIN USING<br />SELECT tabla1.colum1, tabla2.colum2<br />FROM tabla1<br />JOIN tabla2 USING (JoinColum1, JoinColum2)<br />Select * fromlocationsjoincountriesusing (country_id)<br />
  13. 13. Select * fromlocations, countrieswherelocations.country_id = countries.country_id ;<br />Select * fromjobsjoincountriesusing;<br />
  14. 14. Select * fromdepartments d joinemployees e on (e.employee_id = d.department_id)<br />Select * fromemployees e, departments d wheree.employee_id = d.department_id<br />
  15. 15. Ejercicio<br />Muestre un listado de todos los Gerentes de departamento, liste el nombre el apellido y el nombre del departamento.<br />
  16. 16. Select * from Tabla1 natural join Tabla2 using (column1)<br />Recuerde que USING, ON, y NATURAL son mutuamente excluyentes en el contexto de una misma sentencia.<br />
  17. 17. LeftOuter<br />Selecte.employee_id, e.department_id, d.department_id, d.department_namefromdepartments d LEFT OUTER JOIN employees e ON (d.department_id = e.department_id)<br />
  18. 18. Rightouterjoin<br />Selecte.last_name, d.department_namefromdepartments d rightouterjoinemployees e on (e.department_id = d.department_id) wheree.last_namelike ‘G%’<br />
  19. 19. Producto cartesiano<br />Select * fromjobscrossjoinjob_history;<br />Select * fromjobs j crossjoinjob_historyjhwherej.job_id = ‘AD_PRES’<br />
  20. 20. Quien hace lo que le apasiona nunca tendrá trabajo, tendrá diversión<br />

×