• Kaptnik (6/12/2013)


    Let's say I have this dataset.

    UserIDEmail

    ------------------------------------

    1jamesbond@mi6.com

    1jbond@mi6.com

    1jamesb@mi6.com

    2mpenny@mi6.com

    3q@mi6.com

    3weapons_dept@mi6.com

    How do I pick out just one email address for each user id? I'm struggling to write a query to do it.

    Just as long as I get a result set with 3 user ids, and 3 email addresses, I'm happy. It doesn't matter which email address is selected.

    This:

    select

    UserID,

    Email

    from

    (select

    rn = row_number() over (partition by UserID order by (select null)),

    UserID,

    Email

    from

    yourTableNameHere

    ) dt

    where

    rn = 1;

    Untested, but it should work.