Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Joining three tables

Joining three tables

Scheduled Pinned Locked Moved Database
helptutorial
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Raabi Anony
    wrote on last edited by
    #1

    Hello everybody! I have three tables, namely t1, t2, t3

    Dim cmdText As String
    cmdText = "SELECT t1.StaffName, t2.CampusName
    FROM t1
    INNER JOIN t2
    ON t1.CampusID = t2.CampusID
    ORDER BY t1.StaffName"

    It is working fine. My problems starts when I want to include t3; such that;

       t1.StaffID = t3.StaffID
    

    I don't know; how to get it done. Please note that; StaffID is the Primary Key of t1 and the Secondary Key of t3. Would anyone help me, please!

    L Richard DeemingR 2 Replies Last reply
    0
    • R Raabi Anony

      Hello everybody! I have three tables, namely t1, t2, t3

      Dim cmdText As String
      cmdText = "SELECT t1.StaffName, t2.CampusName
      FROM t1
      INNER JOIN t2
      ON t1.CampusID = t2.CampusID
      ORDER BY t1.StaffName"

      It is working fine. My problems starts when I want to include t3; such that;

         t1.StaffID = t3.StaffID
      

      I don't know; how to get it done. Please note that; StaffID is the Primary Key of t1 and the Secondary Key of t3. Would anyone help me, please!

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Could you describe the structure of those three tables? We'd usually join between a primary and a foreign key, not a secondary one.

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

      1 Reply Last reply
      0
      • R Raabi Anony

        Hello everybody! I have three tables, namely t1, t2, t3

        Dim cmdText As String
        cmdText = "SELECT t1.StaffName, t2.CampusName
        FROM t1
        INNER JOIN t2
        ON t1.CampusID = t2.CampusID
        ORDER BY t1.StaffName"

        It is working fine. My problems starts when I want to include t3; such that;

           t1.StaffID = t3.StaffID
        

        I don't know; how to get it done. Please note that; StaffID is the Primary Key of t1 and the Secondary Key of t3. Would anyone help me, please!

        Richard DeemingR Online
        Richard DeemingR Online
        Richard Deeming
        wrote on last edited by
        #3

        Are you just looking for the syntax to join another table?

        SELECT
        ...
        FROM
        t1
        INNER JOIN t2
        ON t2.CampusID = t1.CampusID
        INNER JOIN t3
        ON t3.StaffID = t1.StaffID
        ORDER BY
        ...
        ;


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        R 1 Reply Last reply
        0
        • Richard DeemingR Richard Deeming

          Are you just looking for the syntax to join another table?

          SELECT
          ...
          FROM
          t1
          INNER JOIN t2
          ON t2.CampusID = t1.CampusID
          INNER JOIN t3
          ON t3.StaffID = t1.StaffID
          ORDER BY
          ...
          ;


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          R Offline
          R Offline
          Raabi Anony
          wrote on last edited by
          #4

          Thank you very much, Richard Deeming, for the help. Have a very good day.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups