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

From: Robert Klemme <shortcutter_at_googlemail.com>
Date: Mon, 19 Sep 2011 23:04:26 +0200
Message-ID: <9dpp2qF27kU1_at_mid.individual.net>



On 09/19/2011 05:38 PM, 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.

It's either multiple rows per userid or one row per userid. How would you imagine a table where userid occurs 10 times but the other values 34 times? This cannot be done with SQL. You either need two queries (one for the unique user ids, one for all the rows) or just one which will then have multiple occurrences of individual userids. I agree to Gerard: we need more specific requirements.

Kind regards

        robert Received on Mon Sep 19 2011 - 16:04:26 CDT

Original text of this message