Re: using distinct in a single column to get multiple rows

From: joel garry <joel-garry_at_home.com>
Date: Tue, 20 Sep 2011 14:09:18 -0700 (PDT)
Message-ID: <7fdbb4e9-f622-4022-9303-854abd2fd6c5_at_fe21g2000vbb.googlegroups.com>



On Sep 20, 1:28 pm, t..._at_m.com wrote:
> On Mon, 19 Sep 2011 10:38:54 -0500, t..._at_m.com wrote:
> >Hi,
>
> >I need to get a unique column but I also need to return multiple rows.
>
> >Using the following doesn't work to get the unique last name since it
> >gets all unique columns.  
>
> >select unique userid, title, address
> >from myTable
> >where etc.........
> >order by userid
>
> >The userid will be returned multiple times because the other columns
> >cause the row to be unique.
>
> >How do I get a unique userid while still returning the other rows.
>
> >Thanks!
> >Dave
>
> Thanks for the replies.
>
> Lets say a table has the following data.
>
> userid  title   zipcode
> -----------------------------
> 1       mgr     12345
> 2       dev     56789
> 1       mgr     56789
>
> And I wanted to return one row for each unique userid such as...
> 1       mgr     12345
> 2       dev     56789
>
> If I use - select unique userid, title, zipcode
> it will return all 3 rows because each row is unique
>
> userid  title   zipcode
> -----------------------------
> 1       mgr     12345
> 2       dev     56789
> 1       mgr     56789
>
> I only want unique userids, so it should return.  I realize that there
> are two different rows for userid = 1 but returning only one would be
> OK.  The last one would be good.
>
> userid  title   zipcode
> -----------------------------
> 1       mgr     56789
> 2       dev     56789
>
> Thanks for any help.
> Dave.

What does "last one" mean?

jg

--
_at_home.com is bogus.
http://www.signonsandiego.com/news/2011/sep/19/probate-trustee-sent-to-prison-for-stealing-from/
Received on Tue Sep 20 2011 - 16:09:18 CDT

Original text of this message