Mark George
Mark George

Reputation: 69

SQL JOIN using data from separate table

I have a set of 3 tables(tableA, tableB, tableC).

tableA contains data for users' master account. tableB contains data for users' sub accounts. tableC contains purchase data for master account.

I am needing to do a JOIN statement originating with the sub account ID in tableB. I need to use that ID to locate the ID of the master account by referencing a column in tableA. I do not need this data in the output. Once I have the master account ID from tableA, I need to retrieve the purchase data in tableC.

Is there a way to do this in a single SQL statement without knowing the master ID and without outputting the data from tableA(master account data).

To sum it up: I have the sub account ID(tableB), need to look up the master account ID(tableA) and then return all of the purchase records stored by master account ID(tableC).

EDIT: This is way easier than I was making it out to be(funny how taking a 5 min break fixes things...). The result was just a simple JOIN statement and only return the columns I needed.

Upvotes: 0

Views: 36

Answers (1)

Ben
Ben

Reputation: 489

select B.field_1, C.field_3
from table B 
join table A on B.key_1 = A.key_1
join table C on A.key_2 = C.key_2 

Upvotes: 2

Related Questions