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. This should be simple

This should be simple

Scheduled Pinned Locked Moved Database
sharepointcollaboration
6 Posts 2 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
    Andy_L_J
    wrote on last edited by
    #1

    I have the following table structure: Company: Id (Int), Name (VarChar) Group: Id (Int), Name (VarChar) Division: Id (Int), GroupId (Int) FK, Name Company_Group: CompanyId (Int) FK, GroupId (Int) FK Team: Id (Int), DivisionId (Int) FK, Name (VarChar) I am trying to retrieve the Team Id and Name according to the CompanyId and DivisionId supplied. Note that it is entirely possible that a team may belong to a division in multiple Company's. I have tried various things but seem to get always get unwanted Teams in the results.

    I don't speak Idiot - please talk slowly and clearly 'This space for rent' Driven to the arms of Heineken by the wife

    B 1 Reply Last reply
    0
    • A Andy_L_J

      I have the following table structure: Company: Id (Int), Name (VarChar) Group: Id (Int), Name (VarChar) Division: Id (Int), GroupId (Int) FK, Name Company_Group: CompanyId (Int) FK, GroupId (Int) FK Team: Id (Int), DivisionId (Int) FK, Name (VarChar) I am trying to retrieve the Team Id and Name according to the CompanyId and DivisionId supplied. Note that it is entirely possible that a team may belong to a division in multiple Company's. I have tried various things but seem to get always get unwanted Teams in the results.

      I don't speak Idiot - please talk slowly and clearly 'This space for rent' Driven to the arms of Heineken by the wife

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

      try this

      select t.id,t.name,d.name,g.name,c.*
      from team t
      inner join division d on d.id = t.divisionid
      inner join [group] g on g.id = d.groupid
      inner join Company_Group cg on cg.groupid = g.id
      inner join company c on c.id = cg.companyid

      Hope it will help you


      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

        try this

        select t.id,t.name,d.name,g.name,c.*
        from team t
        inner join division d on d.id = t.divisionid
        inner join [group] g on g.id = d.groupid
        inner join Company_Group cg on cg.groupid = g.id
        inner join company c on c.id = cg.companyid

        Hope it will help you


        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
        Andy_L_J
        wrote on last edited by
        #3

        Sorry Blu_Boy, not quite the expected results. I may not have explained correctly, I want to get only the Teams from the supplied Company (@CompanyId) and where the supplied DivisionId (and thus referenced GroupId) maps to the GroupId in Company_Group table. This is where I'm stuck. This really should be super easy, but I'm not seeing it tonight.

        I don't speak Idiot - please talk slowly and clearly 'This space for rent' Driven to the arms of Heineken by the wife

        B 1 Reply Last reply
        0
        • A Andy_L_J

          Sorry Blu_Boy, not quite the expected results. I may not have explained correctly, I want to get only the Teams from the supplied Company (@CompanyId) and where the supplied DivisionId (and thus referenced GroupId) maps to the GroupId in Company_Group table. This is where I'm stuck. This really should be super easy, but I'm not seeing it tonight.

          I don't speak Idiot - please talk slowly and clearly 'This space for rent' Driven to the arms of Heineken by the wife

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

          I may be wrong again with query.

          select c.company,g.name,d.name,t.name
          from Company_Group cg
          inner join company c on c.id=cg.companyid
          inner join [group] g on g.id=cg.groupid
          inner join division d on d.id=g.id and d.groupid = cg.groupid
          inner join team t on t.id = d.id


          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

            I may be wrong again with query.

            select c.company,g.name,d.name,t.name
            from Company_Group cg
            inner join company c on c.id=cg.companyid
            inner join [group] g on g.id=cg.groupid
            inner join division d on d.id=g.id and d.groupid = cg.groupid
            inner join team t on t.id = d.id


            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
            Andy_L_J
            wrote on last edited by
            #5

            Thanks for your time Blue_Boy, I have found that the design is flawed and there will have to be a work-around outside of the database.

            I don't speak Idiot - please talk slowly and clearly 'This space for rent' Driven to the arms of Heineken by the wife

            B 1 Reply Last reply
            0
            • A Andy_L_J

              Thanks for your time Blue_Boy, I have found that the design is flawed and there will have to be a work-around outside of the database.

              I don't speak Idiot - please talk slowly and clearly 'This space for rent' Driven to the arms of Heineken by the wife

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

              Andy_L_J wrote:

              hanks for your time Blue_Boy,

              My pleasure to help others :)


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

              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