SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Oct 2004
    Location
    Italy
    Posts
    203
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Conditional list of unique values in column

    Hi all,
    Let's take Table A:

    1 2 3
    ------
    a H X
    a I Z
    a H Z
    b I Z
    b H X
    b I X
    c H X
    c I Z
    c H Z

    I'd like to count and list the unique values in column 3 when the value of column 1 is 'a'... In this case, the query should list
    2: X,Z

    Similarly, I'd like to count and list the unique values in column 1 when the value of column 2 is 'H'... In this case, the query should yield
    3: a,b,c

    I've searched the forum without success. I guess this is not such a tricky question, but I'm in my first steps still...

    Thanks for your help.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by Azuleon
    I'd like to count and list the unique values in column 3 when the value of column 1 is 'a'...
    select distinct `3` where `1`= 'a'

    Quote Originally Posted by Azuleon
    Similarly, I'd like to count and list the unique values in column 1 when the value of column 2 is 'H'...
    select distinct `1` where `2`= 'H'
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Addict
    Join Date
    Oct 2004
    Location
    Italy
    Posts
    203
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is exactly what I did - and got an error...
    Ok, it's late and I should probably get some rest before looking at the problem again... Thanks for the help. I'll post back if I get an error again - I probably just mistyped something


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •