Hi, I'm a beginner in sql so hopefully the masters in here can help me out with a simple problem...
I have 2 tables:
A) BANK_TABLE
BANK_ID BANK_NAME
B001 AAA
B002 BBB
B003 CCC
B004 DDD
...
B) CUSTOMERBANK_TABLE
CUST_ID BANK_ID
C001 B001
C001 B003
C005 B001
C005 B002
C010 B003
C015 B002
C015 B004
...
BANK_TABLE is the master bank table. CUSTOMERBANK_TABLE is linked to BANK_TABLE by BANK_ID (obviously) and stores all the customers' selected banks.
What I want to do is, given a CUST_ID (eg C015) I want to return all the banks from BANK_TABLE, and if a given bank is selected by C015, it will return the CUST_ID. This is the structure that I want the result:
CUST_ID BANK_ID BANK_NAME
<null> B001 AAA
C015 B002 BBB
<null> B003 CCC
C015 B004 DDD
<null> B005 EEE
So the query will return all the banks, and if a bank is selected by a customer who's not C015, it'll return a null/blank CUST_ID, and if the bank is selected by C015, it'll return this CUST_ID.
I hope this is clear enough, will appreciate any feedback :)