-1

I have two tables: I have the claim and policy number given. I want to query table a for its check # then using the result I will like to join/get the detail on the second table B for that check#.

Table A
--------------------
|Bank | Check|Claim|Policy|
---------------------------
|01   | dadf |01234|ABC   |
---------------------------
|02   | asdf |04434|DEF   |
---------------------------

Table B
-------------------------
|Bank | Check|Address    |
--------------------------
|01   | dadf |2 Jones St.|
--------------------------

I will like to query the first table A. Then using the value for check column join to its counterpart on B

Table A contains basic payment information and Table B contains the detailed payment information.

Afamee
  • 5,160
  • 9
  • 38
  • 43

2 Answers2

1
Select B.*
 From  TableA A
 Join  TableB B on (A.Bank=B.Bank and A.Check=B.Check)
 Where A.Claim = 'xxx' and  A.Policy = 'yyy'

This will return data from TableB only

John Cappelletti
  • 79,615
  • 7
  • 44
  • 66
  • I am missing the part where on how to take the check # from A and filter table B. I want for every record on A, give me its detailed counterpart on B. But I don't know the check number ahead of time. I only know the claim number – Afamee Oct 07 '16 at 23:27
  • @Afamee After the Join add a Where A.Check = 'xxx' – John Cappelletti Oct 07 '16 at 23:29
  • Not exactly john. What I am asking can easily be done using two separate statements but I want it in one statement. Two statements will look something like: Select check from table a where policy = 'abc' and claim ='345'. Once i have the check from the first statment. The second one will be: Select * from table b where check = . Hopefully this is clearer – Afamee Oct 07 '16 at 23:42
  • @Afamee My answer will perform exactly that – John Cappelletti Oct 07 '16 at 23:50
1
select b* from table a, table b where a.check = b.check

This query will return results from B which has bank account information in A.

If you need to put parameters in

select b* from table a, table b where a.check = b.check and a.bank =@BankName
Nirjhar Vermani
  • 1,215
  • 8
  • 17