Re: using distinct in a single column to get multiple rows
Date: Tue, 20 Sep 2011 15:28:52 -0500
Message-ID: <mfth77d3ii30juusahlt2one1memq44hsj_at_4ax.com>
On Mon, 19 Sep 2011 10:38:54 -0500, test_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.
Received on Tue Sep 20 2011 - 15:28:52 CDT