Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How To Check If a Record in Table 1 Exist in Table 3

Status
Not open for further replies.

bodots

Technical User
Feb 20, 2012
1
PH
Hello Everyone...I am a new and trying to learn SQL programming. I want to check if a particular record in table 1 has already a record in table 3. Here's my table structure.

History - Table 3 Relation - Table 2 Account - Table 1
----------------- ------------------ ------------------
custID custID custAccount
custAccount CustAccount

I cannot set a relation directly from table 1 into table 3 because there is no custID column in table 1. I have to pass to table 2.

What I want to check is if the Relation.custID of Account.custAccount has already a record in History.

Thanks and regards
 
select a.custAccount, r.custID, r.custAccount, H.custID, H.custAccount
from Account a
join Relation r
on R.custAccount = A.custAccount
join History H
on R.custAccount = H.custAccount
and R.custID = H.custID

If H.custID, H.custAccount are null then they don't exist.

Simi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top