Oracle query of intersection of two data tables

Source: Internet
Author: User
Tags how to use sql
Oracle query of intersection of two data tables

Oracle query of intersection of two data tables

The ORACLE tutorial is: query the intersection of two data tables in Oracle.

Oracle relational database management system is a popular relational database system in the world. It is an extremely powerful, flexible, and complex system. It is said that this idea should be applied to oracle, that is, almost any idea can be implemented in SQL.

The following describes how to use SQL to query the same data in two Oracle data tables. I feel that these two methods are highly efficient and easy to use.

Method 1: Use the intersect Operator

The intersect operator is used to merge two queries and return records in both queries, that is, the intersection of the two query results, provided that the number and Data Type of the two query columns must be identical.

Example:

Data Structure of Table:


Data Structure of Table B:



The data in table A is:

('123456', 'Han jia'), ('1234568', 'ding yi ')

The data in table B is:

('20140901', 'hangzhou', 99), ('20140901', 'tingyi', 89), ('20170901', 'xujing', 94)

Run the following query in oracle to display the query results:

[NextPage]

Method 2: in Clause

The in clause can create a list for the values calculated by the where clause in the subquery. This method differs from the previous method in that the previous method compares multiple columns but only uses one intersect, and an in clause is used to compare one column of two subqueries, to compare several columns, you must use several in clauses. The following example shows how to obtain the intersection of two queries.

Take Data Tables A and B as an example. Run the following query in oracle and the query result is displayed:


The query result 2 is shown.


The above is the author's experience in using oracle7.3. If you have any improper information, please do not give us any further advice.

Previous Page

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.