Unix Technical Forum

SQL Query and Distinct

This is a discussion on SQL Query and Distinct within the MS SQL ODBC forums, part of the Microsoft SQL Server category; --> What should be the SQL Query syntax to get the result: Basicaly it's a dinstinct on "Name" but the ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > MS SQL ODBC

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 09:08 PM
Nicolas
 
Posts: n/a
Default SQL Query and Distinct

What should be the SQL Query syntax to get the result:
Basicaly it's a dinstinct on "Name" but the DocUNID is always quicking in

Query not working: SELECT DISTINCT sysEnum.Name, sysEnum.docUNID FROM
sysEnum ORDER BY sysEnum.Name ASC;

Desired Results:
{F77A1DCD-3948-4761-B38F-C5DD0A823196} ListType
{CC626E01-A3AE-444B-BB89-075DEF192725} Module
{7928EE15-C6B2-4F53-B9C9-7B8BED227574} UserType




Here is the table "sysEnum"
DOCUNID
Name

{F77A1DCD-3948-4761-B38F-C5DD0A823196} ListType
{E0F887EA-7573-4D00-9DE2-43D68435F9CB} ListType
{BB83F135-608E-4104-A5A4-2E1D26AEE6DA} ListType
{CC626E01-A3AE-444B-BB89-075DEF192725} Module
{3C6A6B47-1DCE-42CB-8859-66D6BAB479B5} Module
{CF7678C2-39BE-4A7A-9695-48445C99C8FF} Module
{7928EE15-C6B2-4F53-B9C9-7B8BED227574} UserType
{0E3AA5C8-953F-4146-A7EB-92164100C67A} UserType
{942CCCB1-CBCB-4B47-8BA6-EF34CEA1DA03} UserType
{5CA375D8-87ED-4FE3-83B9-4098CC3AB73E} UserType


Thanks for the help
Nicolas


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-27-2008, 09:08 PM
Sue Hoegemeier
 
Posts: n/a
Default Re: SQL Query and Distinct

If you are only returning one row for each Name, what
criteria do you need for that one row and the DocUNID
returned for that one row? If you don't care, you can use
something like:
SELECT Max(sysEnum.DocUNID), SysEnum.Name
FROM sysEnum
GROUP BY SysEnum.Name

-Sue

On Wed, 22 Mar 2006 17:56:06 -0500, "Nicolas"
<nliebel@hotmail.com> wrote:

>What should be the SQL Query syntax to get the result:
>Basicaly it's a dinstinct on "Name" but the DocUNID is always quicking in
>
>Query not working: SELECT DISTINCT sysEnum.Name, sysEnum.docUNID FROM
>sysEnum ORDER BY sysEnum.Name ASC;
>
>Desired Results:
>{F77A1DCD-3948-4761-B38F-C5DD0A823196} ListType
>{CC626E01-A3AE-444B-BB89-075DEF192725} Module
>{7928EE15-C6B2-4F53-B9C9-7B8BED227574} UserType
>
>
>
>
>Here is the table "sysEnum"
>DOCUNID
>Name
>
>{F77A1DCD-3948-4761-B38F-C5DD0A823196} ListType
>{E0F887EA-7573-4D00-9DE2-43D68435F9CB} ListType
>{BB83F135-608E-4104-A5A4-2E1D26AEE6DA} ListType
>{CC626E01-A3AE-444B-BB89-075DEF192725} Module
>{3C6A6B47-1DCE-42CB-8859-66D6BAB479B5} Module
>{CF7678C2-39BE-4A7A-9695-48445C99C8FF} Module
>{7928EE15-C6B2-4F53-B9C9-7B8BED227574} UserType
>{0E3AA5C8-953F-4146-A7EB-92164100C67A} UserType
>{942CCCB1-CBCB-4B47-8BA6-EF34CEA1DA03} UserType
>{5CA375D8-87ED-4FE3-83B9-4098CC3AB73E} UserType
>
>
>Thanks for the help
>Nicolas
>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-27-2008, 09:08 PM
Nicolas
 
Posts: n/a
Default Re: SQL Query and Distinct

Thank you Sue for the help. It works with little modification as DocUNID is
uniqueidentifier

SELECT Max(CAST(sysEnum.DocUNID AS VARCHAR(50))) AS DocUNID, SysEnum.Name
FROM sysEnum
GROUP BY SysEnum.Name

Again thank you
Nicolas

"Sue Hoegemeier" <Sue_H@nomail.please> wrote in message
news:78942256db8ujbb1ekhc4oantlaoae2bdb@4ax.com...
> If you are only returning one row for each Name, what
> criteria do you need for that one row and the DocUNID
> returned for that one row? If you don't care, you can use
> something like:
> SELECT Max(sysEnum.DocUNID), SysEnum.Name
> FROM sysEnum
> GROUP BY SysEnum.Name
>
> -Sue
>
> On Wed, 22 Mar 2006 17:56:06 -0500, "Nicolas"
> <nliebel@hotmail.com> wrote:
>
> >What should be the SQL Query syntax to get the result:
> >Basicaly it's a dinstinct on "Name" but the DocUNID is always quicking in
> >
> >Query not working: SELECT DISTINCT sysEnum.Name, sysEnum.docUNID FROM
> >sysEnum ORDER BY sysEnum.Name ASC;
> >
> >Desired Results:
> >{F77A1DCD-3948-4761-B38F-C5DD0A823196} ListType
> >{CC626E01-A3AE-444B-BB89-075DEF192725} Module
> >{7928EE15-C6B2-4F53-B9C9-7B8BED227574} UserType
> >
> >
> >
> >
> >Here is the table "sysEnum"
> >DOCUNID
> >Name
> >
> >{F77A1DCD-3948-4761-B38F-C5DD0A823196} ListType
> >{E0F887EA-7573-4D00-9DE2-43D68435F9CB} ListType
> >{BB83F135-608E-4104-A5A4-2E1D26AEE6DA} ListType
> >{CC626E01-A3AE-444B-BB89-075DEF192725} Module
> >{3C6A6B47-1DCE-42CB-8859-66D6BAB479B5} Module
> >{CF7678C2-39BE-4A7A-9695-48445C99C8FF} Module
> >{7928EE15-C6B2-4F53-B9C9-7B8BED227574} UserType
> >{0E3AA5C8-953F-4146-A7EB-92164100C67A} UserType
> >{942CCCB1-CBCB-4B47-8BA6-EF34CEA1DA03} UserType
> >{5CA375D8-87ED-4FE3-83B9-4098CC3AB73E} UserType
> >
> >
> >Thanks for the help
> >Nicolas
> >

>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:12 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com