Home All Groups Group Topic Archive Search About

Use DISTINCT and still retrieve all columns

Author
19 May 2006 6:10 PM
Bank
I'm sure this is an old question.

I want to exclude duplicates in one column while still pulling all columns
as if I used
SELECT *.  Can this be done?

Thanks, Bank

Author
19 May 2006 6:18 PM
Adam Machanic
What does "exclude duplicates" mean?  How will you handle the OTHER columns
in the table?  What if they have different values for rows that have
duplicate values of the column in question?


--
Adam Machanic
Pro SQL Server 2005, available now
http://www.apress.com/book/bookDisplay.html?bID=457
--


Show quote
"Bank" <B***@discussions.microsoft.com> wrote in message
news:49DDBF29-5F95-4D5B-BA4E-BA9EDB9F4EB8@microsoft.com...
> I'm sure this is an old question.
>
> I want to exclude duplicates in one column while still pulling all columns
> as if I used
> SELECT *.  Can this be done?
>
> Thanks, Bank
Author
19 May 2006 6:42 PM
Johnny D
SELECT min(col1), min(col2), uniquecolumn
FROM tablename
GROUP BY uniquecolumn
Author
19 May 2006 6:42 PM
David Portas
Bank wrote:
> I'm sure this is an old question.
>
> I want to exclude duplicates in one column while still pulling all columns
> as if I used
> SELECT *.  Can this be done?
>

Yes.

Read my signature. If you give us a better spec we may be able to help
you.

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--

AddThis Social Bookmark Button