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. Join Query returning duplicated rows

Join Query returning duplicated rows

Scheduled Pinned Locked Moved Database
databasesql-serverquestion
3 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.
  • D Offline
    D Offline
    devenv exe
    wrote on last edited by
    #1

    SELECT
    [Sheet1$].Sheet1DetailId,
    [Sheet1$].Sheet1Id,
    [Sheet2$].Sheet2Id,
    LTrim(RTrim([Sheet3$].Mission)) + '-' + CStr(Format('01-' + [Sheet3$].Sheet3Date,"mm/dd/yyyy")) AS Sheet3DateColumn,
    [Sheet1$].one,
    [Sheet1$].two,
    [Sheet1$].three,
    [Sheet1$].four,
    [Sheet1$].five,
    [Sheet1$].six,
    [Sheet1$].seven,
    [Sheet1$].eight,
    [Sheet1$].nine,
    [Sheet1$].ten,
    LTRIM(RTRIM([Sheet2$].Name)) AS Sheet2Name
    FROM (([Sheet1$])
    INNER JOIN [Sheet2$] ON [Sheet1$].Id = [Sheet2$].Sheet2Id)
    INNER JOIN [Sheet3$] ON [Sheet1$].Id = [Sheet3$].Sheet3Id

    In SSIS 2005 Excel source, i have set the data access mode to SQL command and typed in the above query to get data from 3 Microsoft excel sheets(sheet1, sheet2, sheet3). The intention is to get all rows in sheet1 with their corresponding reference values in sheets 2 & 3 but for some strange reason, every row in sheet1 is being returned twice. I can't seem to figure out what i am doing wrong in query?

    "Coming soon"

    M N 2 Replies Last reply
    0
    • D devenv exe

      SELECT
      [Sheet1$].Sheet1DetailId,
      [Sheet1$].Sheet1Id,
      [Sheet2$].Sheet2Id,
      LTrim(RTrim([Sheet3$].Mission)) + '-' + CStr(Format('01-' + [Sheet3$].Sheet3Date,"mm/dd/yyyy")) AS Sheet3DateColumn,
      [Sheet1$].one,
      [Sheet1$].two,
      [Sheet1$].three,
      [Sheet1$].four,
      [Sheet1$].five,
      [Sheet1$].six,
      [Sheet1$].seven,
      [Sheet1$].eight,
      [Sheet1$].nine,
      [Sheet1$].ten,
      LTRIM(RTRIM([Sheet2$].Name)) AS Sheet2Name
      FROM (([Sheet1$])
      INNER JOIN [Sheet2$] ON [Sheet1$].Id = [Sheet2$].Sheet2Id)
      INNER JOIN [Sheet3$] ON [Sheet1$].Id = [Sheet3$].Sheet3Id

      In SSIS 2005 Excel source, i have set the data access mode to SQL command and typed in the above query to get data from 3 Microsoft excel sheets(sheet1, sheet2, sheet3). The intention is to get all rows in sheet1 with their corresponding reference values in sheets 2 & 3 but for some strange reason, every row in sheet1 is being returned twice. I can't seem to figure out what i am doing wrong in query?

      "Coming soon"

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

      What I normally do i this case is to comment out the joins until I identify which one is causing the duplicates, then I filter to 1 row and go hunting through the data to find the cause.

      Never underestimate the power of human stupidity RAH

      1 Reply Last reply
      0
      • D devenv exe

        SELECT
        [Sheet1$].Sheet1DetailId,
        [Sheet1$].Sheet1Id,
        [Sheet2$].Sheet2Id,
        LTrim(RTrim([Sheet3$].Mission)) + '-' + CStr(Format('01-' + [Sheet3$].Sheet3Date,"mm/dd/yyyy")) AS Sheet3DateColumn,
        [Sheet1$].one,
        [Sheet1$].two,
        [Sheet1$].three,
        [Sheet1$].four,
        [Sheet1$].five,
        [Sheet1$].six,
        [Sheet1$].seven,
        [Sheet1$].eight,
        [Sheet1$].nine,
        [Sheet1$].ten,
        LTRIM(RTRIM([Sheet2$].Name)) AS Sheet2Name
        FROM (([Sheet1$])
        INNER JOIN [Sheet2$] ON [Sheet1$].Id = [Sheet2$].Sheet2Id)
        INNER JOIN [Sheet3$] ON [Sheet1$].Id = [Sheet3$].Sheet3Id

        In SSIS 2005 Excel source, i have set the data access mode to SQL command and typed in the above query to get data from 3 Microsoft excel sheets(sheet1, sheet2, sheet3). The intention is to get all rows in sheet1 with their corresponding reference values in sheets 2 & 3 but for some strange reason, every row in sheet1 is being returned twice. I can't seem to figure out what i am doing wrong in query?

        "Coming soon"

        N Offline
        N Offline
        NitinDhapte
        wrote on last edited by
        #3

        Dear, It happens only when the multiple records are available with the correspondence of [Sheet1$].Id into the [Sheet2$] ([Sheet2$].Sheet2Id) Or [Sheet3$] ([Sheet3$].Sheet3Id). Please check with the multiple records into the Both the Sheet 2 & 3. If you dont want to remove the multiple records from those sheets then Add distinct clause into the SELECT Query.

        SELECT DISTINCT
        [Sheet1$].Sheet1DetailId,
        [Sheet1$].Sheet1Id,
        [Sheet2$].Sheet2Id,
        LTrim(RTrim([Sheet3$].Mission)) + '-' + CStr(Format('01-' + [Sheet3$].Sheet3Date,"mm/dd/yyyy")) AS Sheet3DateColumn,
        [Sheet1$].one,
        [Sheet1$].two,
        [Sheet1$].three,
        [Sheet1$].four,
        [Sheet1$].five,
        [Sheet1$].six,
        [Sheet1$].seven,
        [Sheet1$].eight,
        [Sheet1$].nine,
        [Sheet1$].ten,
        LTRIM(RTRIM([Sheet2$].Name)) AS Sheet2Name
        FROM (([Sheet1$])
        INNER JOIN [Sheet2$] ON [Sheet1$].Id = [Sheet2$].Sheet2Id)
        INNER JOIN [Sheet3$] ON [Sheet1$].Id = [Sheet3$].Sheet3Id

        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