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. how to return the douplictate records across only some column using SQL Query ? please help me ! :

how to return the douplictate records across only some column using SQL Query ? please help me ! :

Scheduled Pinned Locked Moved Database
databasetutorialhelpquestion
6 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.
  • A Offline
    A Offline
    AJ Hoge
    wrote on last edited by
    #1

    Hi All , If have table contains of seven columns or more, and i need to return the douplictate records across only three column.how i can writ this using SQL query ? for example i have this table :

    Clmn1 | Clmn2 | Clmn3 | Clmn4 .......|Clmn7
    AJ 35 25 0 19
    BQ 10 12 1 8
    KS 35 25 3 19

    i need to return all records that have duplicat value in this three columns only "Clmn2" , "Clmn3" and "Colmn7" . like this:

    Clmn1 | Clmn2 | colmn3 | clmn4 .......|colmn7
    AJ 35 25 0 ** 19**

    Thanks,

    KS 35 25 3 ** 19**

    L B 2 Replies Last reply
    0
    • A AJ Hoge

      Hi All , If have table contains of seven columns or more, and i need to return the douplictate records across only three column.how i can writ this using SQL query ? for example i have this table :

      Clmn1 | Clmn2 | Clmn3 | Clmn4 .......|Clmn7
      AJ 35 25 0 19
      BQ 10 12 1 8
      KS 35 25 3 19

      i need to return all records that have duplicat value in this three columns only "Clmn2" , "Clmn3" and "Colmn7" . like this:

      Clmn1 | Clmn2 | colmn3 | clmn4 .......|colmn7
      AJ 35 25 0 ** 19**

      Thanks,

      KS 35 25 3 ** 19**

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

      Hint: Use GROUP BY clause with HAVING COUNT(*) > 0

      A 1 Reply Last reply
      0
      • A AJ Hoge

        Hi All , If have table contains of seven columns or more, and i need to return the douplictate records across only three column.how i can writ this using SQL query ? for example i have this table :

        Clmn1 | Clmn2 | Clmn3 | Clmn4 .......|Clmn7
        AJ 35 25 0 19
        BQ 10 12 1 8
        KS 35 25 3 19

        i need to return all records that have duplicat value in this three columns only "Clmn2" , "Clmn3" and "Colmn7" . like this:

        Clmn1 | Clmn2 | colmn3 | clmn4 .......|colmn7
        AJ 35 25 0 ** 19**

        Thanks,

        KS 35 25 3 ** 19**

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

        Hi,I hope this will help you

        SELECT
        (SELECT top 1 m2.Clmn1 FROM mytable m2 WHERE m2.Clmn2= m.Clmn2) Clmn1 ,--by this subquery you get first value of clmn1 column
        clmn2,clmn3,clmn7
        FROM mytable m
        GROUP BY m.clmn2,m.clmn3,m.clm7
        HAVING
        COUNT (col2) > 0 AND
        COUNT (col3) > 0 AND
        COUNT (col7) > 0


        I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com

        A 1 Reply Last reply
        0
        • L Lost User

          Hint: Use GROUP BY clause with HAVING COUNT(*) > 0

          A Offline
          A Offline
          AJ Hoge
          wrote on last edited by
          #4

          you know , Your Are Great !! Many thanks, could you please allow me to ask you a question : i wrote this:

          SELECT
          

          and it is work , but are there better than this way ? becuse when i put Column1 column in the nested select clause with out to be in group by cluase , i got error that show " the coulmn1 is not in the agregation function " so why this is happen? . instade of that i use join to get Column1 , was what i did right ?

          1 Reply Last reply
          0
          • B Blue_Boy

            Hi,I hope this will help you

            SELECT
            (SELECT top 1 m2.Clmn1 FROM mytable m2 WHERE m2.Clmn2= m.Clmn2) Clmn1 ,--by this subquery you get first value of clmn1 column
            clmn2,clmn3,clmn7
            FROM mytable m
            GROUP BY m.clmn2,m.clmn3,m.clm7
            HAVING
            COUNT (col2) > 0 AND
            COUNT (col3) > 0 AND
            COUNT (col7) > 0


            I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com

            A Offline
            A Offline
            AJ Hoge
            wrote on last edited by
            #5

            yeeees !! Blue_Boy , realy realy i appreciate your reply. you are great and helpfull. yor answer is very celever . Many Thanks

            B 1 Reply Last reply
            0
            • A AJ Hoge

              yeeees !! Blue_Boy , realy realy i appreciate your reply. you are great and helpfull. yor answer is very celever . Many Thanks

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

              You are always welcome bro :)


              I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com

              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