Detailed explanation of complex SQL query statements in Oracle (1/4)

Source: Internet
Author: User

1. Use of query statements
Use a SELECT statement and a subquery (subquery) to return data from one or more tables, views, and entities.

1.1 Related subqueries
You can use a subquery (as subquery) or in or exists as part of a condition of a where, such a query is called a subquery
. A subquery in a where can contain a SELECT statement
The. Where can contain in,exists statements
. You can nest up to 16 layers
. Too many layers can affect performance
[Example] Simple subquery instance
Inquire whether some experts apply for the fund project in the name of the Institute, and apply for the project with the University department as the unit
(Only one unit is required to apply)
Sql> CREATE TABLE Univ_subject
2 (
3 name VARCHAR2 () NOT NULL,
4 per_id number NOT NULL,
5 dept_name varchar2 (20)
6);
sql> INSERT into univ_subject values (' gaoqianjing ', 1001, ' Information Engineering Department ');
sql> INSERT into univ_subject values (' wangbing ', 1002, ' Physics Department ');
sql> INSERT into univ_subject values (' liming ', 1003, ' chemistry Department ');
===============
Sql> CREATE TABLE Colle_subject
2 (
3 colle_name varchar2 (20),
4 per_id Number
5);
sql> INSERT into colle_subject values (' E-Institute ', 1001);
sql> INSERT into colle_subject values (' Physics Institute ', 1005);
================
Sql> Select Name,per_id,dept_name from Univ_subject where per_id in
2 (select per_id from Colle_subject);

Name per_id Dept_name
------------          ---------     --------------------
Gaoqianjing 1001 Department of Information Engineering

Home 1 2 3 4 last page
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.