Query records with the same primary key but different values in other fields in the two tables.

Source: Internet
Author: User

Table rpt_pro_elec.pdf and table rpt_pro_elecfee1,

The two tables have the same structure, that is, the primary keys and fields are the same.

The primary keys are: dept_id, trade_code, elec_type_old, elec_type_new, rpt_month, tou_tag, diff_price_type, htrade_code,

Now all I need to do is find records with the same primary key but different values in other fields in the two tables.

========================================================== ======================
Intersect, minus is depressed
SQL> Create Table minus1 (T1 varchar2 (20), T2 varchar2 (20 ));

The table has been created.

SQL> Create Table minus2 (T1 varchar2 (20), T2 varchar2 (20 ));

The table has been created.

SQL> insert into minus1 ('1', '01 ');
Insert into minus1 ('1', '01 ')
*
Row 3 has an error:
ORA-00928: Missing select keywords

SQL> insert into minus1 values ('1', '01 ');

One row has been created.

SQL> insert into minus1 values ('2', '02 ');

One row has been created.

SQL> insert into minus2 values ('2', '02 ');

One row has been created.

SQL> insert into minus2 values ('1', '01 ');

One row has been created.

SQL> insert into minus2 values ('3', '03 ');

One row has been created.

SQL> insert into minus1 values ('4', '04 ');

One row has been created.

SQL> commit;

Submitted.

SQL> select * From minus1 minus select * From minus2;

T1 T2
----------------------------------------
4 04

SQL> (select * From minus1 minus select * From minus2) Union (select * From Minu
S2 minus select * From minus1 );

T1 T2
----------------------------------------
3 03
4 04

SQL> select * From minus1 intersect select * From minus2;

T1 T2
----------------------------------------
1 01
2 02

SQL>

 

==========================================

Example:

Select to_char (irowukid) from tbrdb09 where id = '2017 _ 1' minus select irowukid from sqsaa. vcooperationinfotemp where id = '2017 _ 1 ';

Select count (*) from sqsaa. vcooperationinfotemp where id = '2017 _ 1' minus select to_char (irowukid) from tbrdb09 where id = '2017 _ 1 ';

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.