Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Need to Select Uniqueidentifer column but Group by

Author  Topic 

azamsharp
Posting Yak Master

201 Posts

Posted - 2009-10-20 : 15:12:29
Hi,

I need to have a uniqueidentifier column in the select statement but I also have a groupby at the end. What can I do?

Mohammad Azam
www.azamsharp.net

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-10-20 : 15:15:51
sorry your question is not clear. do you mean you need to group by uniqueidentifier column?
Go to Top of Page

azamsharp
Posting Yak Master

201 Posts

Posted - 2009-10-20 : 15:24:17
Hi,

I am selecting some records from the database table and one of the records in a uniqueidentifier. At the end of my query I am performing a group by. I cannot perform group by since one of the fields is uniqueidentifier.

Also, I don't want that column/field to take part in the groupby.




Mohammad Azam
www.azamsharp.net
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2009-10-20 : 15:42:36
If you supply some sample data and expected output we can probably help you better. This link should help with that: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

But, here is a guess:
SELECT 
*
FROM
(
SELECT
Col1,
Col2,
Col3,
UniqueCol,
ROW_NUMBER() OVER (PARTITION BY Col1, Col2, Col3 ORDER BY UniqueCol) AS RowNum
FROM
MyTable
) AS T
WHERE
T.RowNum = 1
Go to Top of Page
   

- Advertisement -