I have a table table1
containing only the duplicate person_number
and its corresponding account_number
. How do I query for these duplicate person_number
from main table master_table
which has no person_number
column but only the account_number
column?
table1
person_number | account_number |
---|
11 | 1 |
12 | 2 |
13 | 3 |
14 | 4 |
15 | 5 |
master_table
account_number | account_balance |
---|
1 | 238989 |
2 | 4889895 |
3 | 68897 |
4 | 298729 |
5 | 387745 |
6 | 354655 |
7 | 553455 |
8 | 35545 |
I would like to filter the master_table
to only contain the account_number
present in table1
resultant_table_of_duplicates
account_number | account_balance |
---|
1 | 238989 |
2 | 4889895 |
3 | 68897 |
4 | 298729 |
5 | 387745 |
2条答案
按热度按时间r3i60tvu1#
As already pointed in the comments section, one idea to carry out this task is using the
EXISTS
operator inside theWHERE
clause, by checking all records from mastertable whose "account_number" can be found inside table1.Output:
Check the demo here .
h6my8fg22#
You can insert Base data with the following statements: