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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Get unique value in INNER JOIN in SQL server 2005 query

Get unique value in INNER JOIN in SQL server 2005 query

Scheduled Pinned Locked Moved Database
databasesql-serversysadminquestion
4 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.
  • S Offline
    S Offline
    salon
    wrote on last edited by
    #1

    I am joining two tables with INNER JOIN and I am getting duplicate entries. I used DISTINCT but its not working. Do we have some other keywords for the same? Thanks in advance,

    A B V 3 Replies Last reply
    0
    • S salon

      I am joining two tables with INNER JOIN and I am getting duplicate entries. I used DISTINCT but its not working. Do we have some other keywords for the same? Thanks in advance,

      A Offline
      A Offline
      Alsvha
      wrote on last edited by
      #2

      You do not get duplicate entries if you can't DISTINCT them away. At least one of the values in your SELECT list differs from the others, making the rows different. DISTINCT will remove "duplicated" rows.

      --------------------------- Blogging about SQL, Technology and many other things

      1 Reply Last reply
      0
      • S salon

        I am joining two tables with INNER JOIN and I am getting duplicate entries. I used DISTINCT but its not working. Do we have some other keywords for the same? Thanks in advance,

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

        try to use TOP 1


        I Love T-SQL "Don't torture yourself,let the life to do it for you."

        1 Reply Last reply
        0
        • S salon

          I am joining two tables with INNER JOIN and I am getting duplicate entries. I used DISTINCT but its not working. Do we have some other keywords for the same? Thanks in advance,

          V Offline
          V Offline
          Vinay Dornala
          wrote on last edited by
          #4

          Hi, Try in this way, I am not sure this will resolve your question. Distinct will impact on performance ( number of cpu reads) WHILE EXISTS (select * FROM Table1 GROUP BY col1,col2.., HAVING count(*) > 1) BEGIN SET ROWCOUNT 1 DELETE e FROM Table1 e.empid WHERE EXISTS (select empid from @tab i where i.empid = e.empid AND i.name = e.name GROUP BY i.empid, i.name HAVING count(*) > 1) SET ROWCOUNT 0 END

          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