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
 General SQL Server Forums
 New to SQL Server Programming
 SELECT Distinct

Author  Topic 

visa123
Yak Posting Veteran

54 Posts

Posted - 2010-10-15 : 08:51:39

I have a Distinct all the values for cid based.

below are the values

cid cname dest

1 xxx it

1 yyy it

2 zzz ct

Select Distinct * from tablename

But the count not coming properly bec of dest cname field

any help pls


Visa.G

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2010-10-15 : 09:06:26
SELECT cid, cname, dest, COUNT(*)
FROM table
GROUP BY cid, cname, dest

- Lumbago

My blog (yes, I have a blog now! just not that much content yet)
-> www.thefirstsql.com
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-10-17 : 02:28:46
i think op meant

SELECT t.*,t1.Cnt
FROM Table t
INNER JOIN (SELECT cid,COUNT(*) AS Cnt, MIN(cname) AS MinName
FROM Table
GROUP BY cid)t1
ON t1.cid = t.cid
AND t1.MinName=t.cname


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -