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. Distinct records problem

Distinct records problem

Scheduled Pinned Locked Moved Database
helptutorial
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.
  • P Offline
    P Offline
    psamy
    wrote on last edited by
    #1

    Hi , I want to read the distinct records with multiple columns. for example, tableA -------- OID CODE 1 READ 2 READ 3 WRITE 4 WRITE select distinct CODE, OID from tableA it gives, READ 1 READ 2 WRITE 3 WRITE 4 but expected result was, READ 1 WRITE 3

    S R 2 Replies Last reply
    0
    • P psamy

      Hi , I want to read the distinct records with multiple columns. for example, tableA -------- OID CODE 1 READ 2 READ 3 WRITE 4 WRITE select distinct CODE, OID from tableA it gives, READ 1 READ 2 WRITE 3 WRITE 4 but expected result was, READ 1 WRITE 3

      S Offline
      S Offline
      seea
      wrote on last edited by
      #2

      man this sql script is not work like this .... u should use the group by function to get that effect and any aggr functions select CODE, min(OID) from tableA group by CODE This should fetch you the result

      thanks, SeEa

      1 Reply Last reply
      0
      • P psamy

        Hi , I want to read the distinct records with multiple columns. for example, tableA -------- OID CODE 1 READ 2 READ 3 WRITE 4 WRITE select distinct CODE, OID from tableA it gives, READ 1 READ 2 WRITE 3 WRITE 4 but expected result was, READ 1 WRITE 3

        R Offline
        R Offline
        ra ra ra ra
        wrote on last edited by
        #3

        hmm not sure exactly what your looking for so I'm going to assume you want: the lowest OID for each distinct CODE which is: select CODE, MIN(OID) from tableA group by CODE which would give your desired result. DISTINCT is no way appropriate for what your trying to do in this case!

        P 1 Reply Last reply
        0
        • R ra ra ra ra

          hmm not sure exactly what your looking for so I'm going to assume you want: the lowest OID for each distinct CODE which is: select CODE, MIN(OID) from tableA group by CODE which would give your desired result. DISTINCT is no way appropriate for what your trying to do in this case!

          P Offline
          P Offline
          psamy
          wrote on last edited by
          #4

          don't assume you have OID in number format OID CODE x READ y READ z WRITE .. this scenorio expected result will be, OID CODE x READ z WRITE

          R S 2 Replies Last reply
          0
          • P psamy

            don't assume you have OID in number format OID CODE x READ y READ z WRITE .. this scenorio expected result will be, OID CODE x READ z WRITE

            R Offline
            R Offline
            ra ra ra ra
            wrote on last edited by
            #5

            if you didn't want us to assume , then you should have stated clearly in your orig post, instead of wasting our time................. dunderhead

            1 Reply Last reply
            0
            • P psamy

              don't assume you have OID in number format OID CODE x READ y READ z WRITE .. this scenorio expected result will be, OID CODE x READ z WRITE

              S Offline
              S Offline
              seea
              wrote on last edited by
              #6

              In that case also teh above approach of grouping by should work !!!

              thanks, SeEa

              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