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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Joins - newb Question

Status
Not open for further replies.

jayvatar

Programmer
Dec 16, 2008
3
US
I have a table A with fields that are foreign key integers for the primary key to another table B. The problem I am having is that I have multiple fields in Table A that are the same foreign keys to the primary key in table B.

For Example:
Table A Field 1 Record 1 = 1
Table A Field 2 Record 1 = 2

Table B Field 1 Record 1 = "YES"
Table B Field 1 Record 2 = "NO"


In other words the integers in Table A are lookups for table B's Records. Whenever I do a SQL call it does not pull the record unless both fields in Table A are the same. I do not want this. What I want is to be able to say that items can be "YES" or "NO" but still exist in the same record from Table A. Can anyone tell me where I am going wrong? Thanks
 
Why not posting the real structure of your A and B tables ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I was trying to condense what I was doing into simple form. My apologies

Table A Record 1 Field 1 = 1 = Record ID
Table A Record 1 Field 2 = 1 = Foreign Key Table B
Table A Record 1 Field 3 = 2 = Foreign Key Table B

Table B Record 1 Field 1 = 1 = Primary Key
Table B Record 1 Field 2 = "YES"
Table B Record 2 Field 1 = 2 = Primary Key
Table B Record 2 Field 2 = "NO"

 
A starting point:
SELECT *
FROM tableA A
INNER JOIN JOIN tableB B1 ON A.Field2 = B1.Field1
INNER JOIN JOIN tableB B2 ON A.Field3 = B2.Field1

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top