Advanced Query method for Oracle Database Multi-Table federated query

Source: Internet
Author: User
Tags joins

  Oracle queries

    One, simple query

ORDER BY

Select T.sno, T.sname, t.ssex from STUDENT t ORDER by

Group BY Enhanced Edition

SELECT P.toma, P.ptype, SUM (P.lastcou) from product P GROUP by Rollup (P.toma, P.ptype)

    Second, advanced query (multi-table connection query)

The concept of Cartesian product:

The so-called Cartesian product, the popular point is refers to contains two sets of arbitrary two elements of the composition of a set. If R has a tuple of M and S has a tuple n, then R and S's Cartesian card

The number of tuples contained in the product is m*n. This rule can be extended to multiple relationships.

Classification:

Internal connection: Select S.sname, r.cno,r.degree from student S, score R where S.sno=r.sno

Connection of equivalent connection------with =

No equivalent connection

External connection (Nothing to write is the inner connection, directly write two table name)---Left outer connection, right outer connection

SELECT * FROM student s left outer joins course C on S.sno=c.cno

Use of (+) modifiers

Select S.sname, r.cno,r.degree from student S, score R where S.sno=r.sno (+)----results equivalent to outer joins

Use of data dictionaries

Self-connect (cheat yourself): select * from Z_course C1, Z_course C2 where C1.cour_code=c2.p_cour_code

Hierarchical query
Connect by PRIOR Connection condition start with start condition

            SELECT * FROM Z_course t connect by prior T.cour_code=t.p_cour_code start with t.cour_name like '% International '

Pseudo-column:

Level: plus a column of display levels

              Select t.*, level from Z_course t connect by prior T.cour_code=t.p_cour_code start with t.cour_name like '% International '

RowNum: Add a column line number

                Select S.*, rownum from student s

Use RowNum to split pages

                  SELECT * FROM (select s.*, rownum rn from student s where rownum<=10) T where t.rn>5

Subqueries (the order in which SQL statements are executed)

Single-line subquery: can use = number

Multi-row subquery: Can not use the = number, can be used in

Use of the EXISTS keyword: whether it exists

              SELECT * FROM student t where exists (select 1 from student t1 where t1.sno=105)

Advanced Query method for Oracle Database Multi-Table federated query

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.