Results 1 to 3 of 3

Thread: is it possible to get data from 3 tables with one SELECT statement?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,168

    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?

  2. #2
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    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

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,168

    Re: is it possible to get data from 3 tables with one SELECT statement?

    Quote Originally Posted by jggtz View Post
    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
  •  



Click Here to Expand Forum to Full Width