Oracle Chapter 13th when one query relies on another query

Source: Internet
Author: User

Advanced subquery subquery (subquery)

Knowledge Point one: the relationship between multi-table joins

For example, want to know which kind of books have been lent out.

Select DISTINCT C.parent_catagory, c.sub_category

From category C, Bookshelf b, bookshelf_checkout BC

where c.category_name = b.category_name and B.title = Bc.title

Distinct keywords go to weight

The relationship between the 3 table associations in this example: to connect the 3 table, you must concatenate two of the tables with the third table.

The 1.CATEGORY table is connected to the Bookshelf table, and the results of their connection are then connected to the Bookshelf_checkout table. Distinct sentence to go heavy

Note: Not every table is connected to every other table. The connection between tables is typically 1 less than the number of tables connected.

Knowledge Point two: correlated subqueries

A.where subqueries where the clause can contain subqueries of a SELECT statement, where the clauses of a subquery can also be nested

Select DISTINCT C.parent_categorty, c.sub_category

From Categort C

where Category_name in

(Select Category_name from Bookshelf

where title in

(select title from Bookshelf_checkout)

);

This query is the same as the query results in the knowledge point one

A: A subquery can reference a column of a table used in its main query (that is, the following example does not have a title column in the Bookshelf table)

Select title from Bookshelf_author

where title in

(select title from Bookshelf

where author_name = ' Setphena hay Gould ')

Oracle Chapter 13th when one query relies on another query

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.