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. MySQL
  4. Using a DISTINCT query

Using a DISTINCT query

Scheduled Pinned Locked Moved MySQL
databasehelpquestion
3 Posts 2 Posters 5 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
    SummerBulb
    wrote on last edited by
    #1

    Hi there, I have tried running a query using the DISTINCT keyword, but the result is not what i am looking for. The table is something like the following:

    name age
    AA 12
    BB 13
    cc 18
    AA 14
    BB 19

    If i query:

    Select Distinct name, age from table;

    i get all the rows. I am intested in a result set that will be:

    name age
    AA 12
    BB 13
    cc 18

    Can anyone help? Thank! Edit: 1. I know that distinct works on the combination of the colunms, giving a distinct set of rows, but that is not what i need. I need it to be distincted by the name. 2. Running

    Select Distinct(name), age from table;

    doesn't give the correct result either.

    modified on Sunday, October 11, 2009 10:37 AM

    S 1 Reply Last reply
    0
    • S SummerBulb

      Hi there, I have tried running a query using the DISTINCT keyword, but the result is not what i am looking for. The table is something like the following:

      name age
      AA 12
      BB 13
      cc 18
      AA 14
      BB 19

      If i query:

      Select Distinct name, age from table;

      i get all the rows. I am intested in a result set that will be:

      name age
      AA 12
      BB 13
      cc 18

      Can anyone help? Thank! Edit: 1. I know that distinct works on the combination of the colunms, giving a distinct set of rows, but that is not what i need. I need it to be distincted by the name. 2. Running

      Select Distinct(name), age from table;

      doesn't give the correct result either.

      modified on Sunday, October 11, 2009 10:37 AM

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

      Just to let you know, i solved the problem.

      select distinct(name), age from table group by name;

      did the job. Thanks.

      T 1 Reply Last reply
      0
      • S SummerBulb

        Just to let you know, i solved the problem.

        select distinct(name), age from table group by name;

        did the job. Thanks.

        T Offline
        T Offline
        T2102
        wrote on last edited by
        #3

        you also might find dense_rank useful, although it may cause problems with Oracle 11g.

        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