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 4 Tables

Joining 4 Tables

Scheduled Pinned Locked Moved Database
helplearning
6 Posts 4 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.
  • A Offline
    A Offline
    ASPnoob
    wrote on last edited by
    #1

    Hi all, suppose I have an app that allows users to search for people based on location, degree held, skills, and experience. How would I join the following tables to achieve what I need:

    Person Table
    PersonID -----Pk
    First Name
    Last Name
    City
    State

    Education Table
    EducationID --PK
    PersonID -----FK
    Degree

    Skills Table
    SkillID ------PK
    PersonID -----FK
    Skill

    JobHistory Table
    HistoryID ----PK
    PersonID -----FK
    Experience

    Thanks in advance for your help.

    M B L 3 Replies Last reply
    0
    • A ASPnoob

      Hi all, suppose I have an app that allows users to search for people based on location, degree held, skills, and experience. How would I join the following tables to achieve what I need:

      Person Table
      PersonID -----Pk
      First Name
      Last Name
      City
      State

      Education Table
      EducationID --PK
      PersonID -----FK
      Degree

      Skills Table
      SkillID ------PK
      PersonID -----FK
      Skill

      JobHistory Table
      HistoryID ----PK
      PersonID -----FK
      Experience

      Thanks in advance for your help.

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      As your joins are many to one (History to Person) you are going to need a number of queries and/or views to get all the different results. I would create view(s) that joined all the tables, using inner joins where where the FK is required and left joins where the FK is optional and then search that view. Alternatively use joins via the PersonID FK.

      Never underestimate the power of human stupidity RAH

      1 Reply Last reply
      0
      • A ASPnoob

        Hi all, suppose I have an app that allows users to search for people based on location, degree held, skills, and experience. How would I join the following tables to achieve what I need:

        Person Table
        PersonID -----Pk
        First Name
        Last Name
        City
        State

        Education Table
        EducationID --PK
        PersonID -----FK
        Degree

        Skills Table
        SkillID ------PK
        PersonID -----FK
        Skill

        JobHistory Table
        HistoryID ----PK
        PersonID -----FK
        Experience

        Thanks in advance for your help.

        B Offline
        B Offline
        Blue_Boy
        wrote on last edited by
        #3

        select p.* ,e.*,s.*,jh.*
        from persons p
        inner join Education e on e.PersonID = p.PersonID
        inner join Skills s on s.PersonID = p.PersonID
        inner join JobHistory jh on jh.PersonID = p.PersonID


        I Love T-SQL "VB.NET is developed with C#.NET" If my post helps you kindly save my time by voting my post.

        A 1 Reply Last reply
        0
        • B Blue_Boy

          select p.* ,e.*,s.*,jh.*
          from persons p
          inner join Education e on e.PersonID = p.PersonID
          inner join Skills s on s.PersonID = p.PersonID
          inner join JobHistory jh on jh.PersonID = p.PersonID


          I Love T-SQL "VB.NET is developed with C#.NET" If my post helps you kindly save my time by voting my post.

          A Offline
          A Offline
          ASPnoob
          wrote on last edited by
          #4

          This looks great but what about the conditions? For instance I want to find someone who meets the following conditions:

          Education = Masters
          Skills = Computer Networking
          Experience = 6 years

          Also I would like the search to match lower case spelling of Masters and Computer Networking, how are those 2 things I've just mentioned achieved. Thanks for your help.

          M 1 Reply Last reply
          0
          • A ASPnoob

            This looks great but what about the conditions? For instance I want to find someone who meets the following conditions:

            Education = Masters
            Skills = Computer Networking
            Experience = 6 years

            Also I would like the search to match lower case spelling of Masters and Computer Networking, how are those 2 things I've just mentioned achieved. Thanks for your help.

            M Offline
            M Offline
            Mycroft Holmes
            wrote on last edited by
            #5

            Add a where clause with the conditions and user LOWER(Education) = 'masters' You are screwed with the 6 Years, this should have been stored as a numeric and then you could use Duration > 6 You may also want to look into SOUNDEX filtering for the text fields

            Never underestimate the power of human stupidity RAH

            1 Reply Last reply
            0
            • A ASPnoob

              Hi all, suppose I have an app that allows users to search for people based on location, degree held, skills, and experience. How would I join the following tables to achieve what I need:

              Person Table
              PersonID -----Pk
              First Name
              Last Name
              City
              State

              Education Table
              EducationID --PK
              PersonID -----FK
              Degree

              Skills Table
              SkillID ------PK
              PersonID -----FK
              Skill

              JobHistory Table
              HistoryID ----PK
              PersonID -----FK
              Experience

              Thanks in advance for your help.

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

              Select TblA.*,TblB.*,TblC.*,TblD.* from persons TblA
              inner join Education TblB on TblB.PersonID = TblA.PersonID
              inner join Skills TblC on TblC.PersonID = TblA.PersonID
              inner join JobHistory TblD on TblD.PersonID = TblA.PersonID

              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