|
-
Aug 5th, 2011, 06:49 PM
#1
Thread Starter
Frenzied Member
is it possible to get data from 3 tables with one SELECT statement?
Let's say I have three tables (tableA, tableB, tableC). Each table has a primary key, and tableB has a foreign key that references tableA, and tableC has a foreign key that references tableB. Could we get one specific record using a select statement that would give us the related data from all three tables?
-
Aug 5th, 2011, 10:22 PM
#2
Re: is it possible to get data from 3 tables with one SELECT statement?
Something like this :
Code:
SELECT TableA.Field1, TableA.Field2, TableB.FieldN, TableC.FieldM
FROM TableA
INNER JOIN TableB ON TableA.PKey = TableB.FKeyA
INNER JOIN TableC ON TableB.PKey = TableC.FKeyB
WHERE TableA.Field1 = 'XXXX'
Just change the fields' names & add the real ones
JG
-
Aug 12th, 2011, 03:08 PM
#3
Thread Starter
Frenzied Member
Re: is it possible to get data from 3 tables with one SELECT statement?
 Originally Posted by jggtz
Something like this :
Code:
SELECT TableA.Field1, TableA.Field2, TableB.FieldN, TableC.FieldM
FROM TableA
INNER JOIN TableB ON TableA.PKey = TableB.FKeyA
INNER JOIN TableC ON TableB.PKey = TableC.FKeyB
WHERE TableA.Field1 = 'XXXX'
Just change the fields' names & add the real ones
JG
Cool, thanks. I'll try it out.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|