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. SQL statement returning duplicates with DISTINCT [modified]

SQL statement returning duplicates with DISTINCT [modified]

Scheduled Pinned Locked Moved Database
databasehelp
3 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.
  • S Offline
    S Offline
    ScottM1
    wrote on last edited by
    #1

    Does anybody know why this SQL statement returns duplicates even though I have included the DISTINCT keyword. There aren't duplicates in the database.

    SELECT DISTINCT BLT_BILLM_TAX.BILLM_TAX_UNO, BLT_BILLM_TAX.BILL_TRAN_UNO, HBM_MATTER.MATTER_CODE, BLT_BILLM_TAX.JURISDIC_CODE,BLT_BILLM_TAX.TAX_CODE, BLT_BILLM_TAX.TAXABL_FEES_AMT, BLT_BILLM_TAX.TAXABL_HARD_AMT, BLT_BILLM_TAX.TAXABL_SOFT_AMT,
    BLT_BILLM_TAX.TAX_ON_FEES_AMT, BLT_BILLM_TAX.TAX_ON_HARD_AMT, BLT_BILLM_TAX.TAX_ON_SOFT_AMT, BLT_BILLM_TAX.FEE_TAX_RATE,
    BLT_BILLM_TAX.DISB_TAX_RATE, CDT_DISB.PERIOD, CDT_DISB.COST_CODE, BLT_BILL.BILL_NUM
    FROM HBM_MATTER
    INNER JOIN CDT_DISB ON HBM_MATTER.MATTER_UNO = CDT_DISB.MATTER_UNO
    INNER JOIN BLT_BILLM_TAX ON CDT_DISB.BILL_TRAN_UNO = BLT_BILLM_TAX.BILL_TRAN_UNO
    INNER JOIN BLT_BILL ON CDT_DISB.BILL_TRAN_UNO = BLT_BILL.TRAN_UNO
    INNER JOIN APT_INVOICE ON CDT_DISB.SOURCE_TRAN_UNO = APT_INVOICE.TRAN_UNO
    WHERE (APT_INVOICE.PERIOD BETWEEN '200601' AND '200601')
    AND (APT_INVOICE.TRAN_UNO = 627167)

    Any help would be appreciated Thanks -- modified at 6:00 Thursday 31st May, 2007 -- modified at 6:01 Thursday 31st May, 2007

    There are 10 types of people in the world, those who understand binary and those who dont.

    K 1 Reply Last reply
    0
    • S ScottM1

      Does anybody know why this SQL statement returns duplicates even though I have included the DISTINCT keyword. There aren't duplicates in the database.

      SELECT DISTINCT BLT_BILLM_TAX.BILLM_TAX_UNO, BLT_BILLM_TAX.BILL_TRAN_UNO, HBM_MATTER.MATTER_CODE, BLT_BILLM_TAX.JURISDIC_CODE,BLT_BILLM_TAX.TAX_CODE, BLT_BILLM_TAX.TAXABL_FEES_AMT, BLT_BILLM_TAX.TAXABL_HARD_AMT, BLT_BILLM_TAX.TAXABL_SOFT_AMT,
      BLT_BILLM_TAX.TAX_ON_FEES_AMT, BLT_BILLM_TAX.TAX_ON_HARD_AMT, BLT_BILLM_TAX.TAX_ON_SOFT_AMT, BLT_BILLM_TAX.FEE_TAX_RATE,
      BLT_BILLM_TAX.DISB_TAX_RATE, CDT_DISB.PERIOD, CDT_DISB.COST_CODE, BLT_BILL.BILL_NUM
      FROM HBM_MATTER
      INNER JOIN CDT_DISB ON HBM_MATTER.MATTER_UNO = CDT_DISB.MATTER_UNO
      INNER JOIN BLT_BILLM_TAX ON CDT_DISB.BILL_TRAN_UNO = BLT_BILLM_TAX.BILL_TRAN_UNO
      INNER JOIN BLT_BILL ON CDT_DISB.BILL_TRAN_UNO = BLT_BILL.TRAN_UNO
      INNER JOIN APT_INVOICE ON CDT_DISB.SOURCE_TRAN_UNO = APT_INVOICE.TRAN_UNO
      WHERE (APT_INVOICE.PERIOD BETWEEN '200601' AND '200601')
      AND (APT_INVOICE.TRAN_UNO = 627167)

      Any help would be appreciated Thanks -- modified at 6:00 Thursday 31st May, 2007 -- modified at 6:01 Thursday 31st May, 2007

      There are 10 types of people in the world, those who understand binary and those who dont.

      K Offline
      K Offline
      kubben
      wrote on last edited by
      #2

      Most likely it is a inner join issue. If there are multiple rows in the table you are joining to, but you are not including any columns from that join you will get duplicates. I would look at removing any unnecessary joins. Hope that helps. Ben

      S 1 Reply Last reply
      0
      • K kubben

        Most likely it is a inner join issue. If there are multiple rows in the table you are joining to, but you are not including any columns from that join you will get duplicates. I would look at removing any unnecessary joins. Hope that helps. Ben

        S Offline
        S Offline
        ScottM1
        wrote on last edited by
        #3

        I don't know what it was but I messed about with it and swapped some stuff around and it seems to work now. Thanks

        There are 10 types of people in the world, those who understand binary and those who dont.

        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