Inquiry in Oracle for two data sheets

xiaoxiao2021-03-06  15

Oracle relational database management system is a popular relational database in the world. It is an extremely powerful, flexible and complex system. It is said that such thoughts should be used when using Oracle, that is, almost any idea in SQL. .

Here's how to use SQL to check the same data of two Oracle data sheet queries, the author feels that these two methods have high efficiency, easy to use. First method: Using OR intertect

The INTERSECT operator uses two queries to return the records existing in the two queries, that is, the intersection of the two query results, the premise is that the number of columns and data types of the two queries must be identical.

for example:

Table A data structure:

Chinese Name Field Name Type Length Student No. Code C 4 Name Name C 8

Table B data structure:

Chinese Name Field Name Type Length Student STUDENT_CODE C 4 Name Student_name C 8 Score Score N 3

The data of Table A is:

('1101', 'South Korean'), ('1102', 'Dishi ")

Table B data is:

('1101', 'South Korean', 99), ('1102', 'Dishi ", (' 1103 ',' Xu Jing ', 94)

Second method: in clause

The IN clause can create a list for the value of the WHERE clause to the WHERE clause. This approach is different from the previous method. The former method is more than a multi-column but only one intertent is used, and a in clause is used to compare a column of two subquers, and a few columns should be used IN clause. The following example shows how to get the intersection of two queries.

Still use A and B two data sheets as an example, run the following query in Oracle, Figure 2 shows the results of this query:

SQL> Select Code, Name from Awhere A.code in (Select Student_code from b) and a.name in (select student_name from b) Order by a.code;

转载请注明原文地址:https://www.9cbs.com/read-45884.html

New Post(0)