What type of query will return the correct results?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dbytes
    New Member
    • Sep 2010
    • 1

    What type of query will return the correct results?

    I have no idea what sql command will return the results I need from 1 table.

    example of table and values

    col1 col2 col3(unique values)
    1 1 abc
    1 1 dev
    1 2 rst
    1 3 ndb
    1 3 mnv

    I need an sql query, that returns the distinct combined values of col1
    and col2 and the first value of that distinct combination from col3.


    return values should be;
    1 1 abc
    1 2 rst
    1 3 ndb
  • Anand Kaushal
    New Member
    • Oct 2010
    • 6

    #2
    This might help

    select r,c1,c2,c3
    from table(
    select row_number() over(partition by c1,c2 order by c3) r, c1, c2, c3 from table(values (1,1, 'abc'), (1, 1, 'dev'),(1, 2, 'rst'),(1, 3, 'ndb'),(1, 3, 'mnv')) t(c1,c2,c3) order by c1,c2,c3
    )
    where r=1

    Comment

    Working...