Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / General / Other SQL Server Topics / November 2007

Tip: Looking for answers? Try searching our database.

Select distinct rows from duplicate rows....

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
sanjeev.atvankar@gmail.com - 28 Nov 2007 13:26 GMT
Dear Gurus,

I have table with following entries

Table name = Customer

Name      Weight
------------  -----------
Sanjeev      85
Sanjeev      75
Rajeev        80
Rajeev        45
Sandy        35
Sandy        30
Harry         15
Harry         45

I need a output as follow

Name      Weight
------------  -----------
Sanjeev      85
Rajeev        80
Sandy        30
Harry          45

OR

Name      Weight
------------  -----------
Sanjeev      75
Rajeev        45
Sandy        35
Harry         15

i.e. only distinct Name should display with only one value of  Weight.
I tried with 'group by' on Name column but it shows me all rows.

Could anyone help me for above.

Thanking in Advance.

Regards
Sanjeev
sanjeev.atvankar@gmail.com
Jason Lepack - 28 Nov 2007 13:45 GMT
select
 [Name],
 max([Weight]) as wgt
from
 [Customer]
group by
 [Name]

Cheers,
Jason Lepack

On Nov 28, 8:26 am, sanjeev.atvan...@gmail.com wrote:
> Dear Gurus,
>
[quoted text clipped - 41 lines]
> Sanjeev
> sanjeev.atvan...@gmail.com
Jason Lepack - 28 Nov 2007 13:47 GMT
Please note that because you don't care which weight you get, max()
can be replaced with min(), first(), last(), etc.

Cheers,
Jason Lepack

On Nov 28, 8:26 am, sanjeev.atvan...@gmail.com wrote:
> Dear Gurus,
>
[quoted text clipped - 41 lines]
> Sanjeev
> sanjeev.atvan...@gmail.com
Madhivanan - 28 Nov 2007 14:27 GMT
> Please note that because you don't care which weight you get, max()
> can be replaced with min(), first(), last(), etc.
[quoted text clipped - 51 lines]
>
> - Show quoted text -

Note that SQL Server doesnt support first() or last() function
SQL Menace - 28 Nov 2007 13:50 GMT
SELECT Name, MAX(Weight) AS Weight
FROM Customer
GROUP BY  Name

or

SELECT Name, MIN(Weight) AS Weight
FROM Customer
GROUP BY  Name

Denis The SQL Menace
http://sqlservercode.blogspot.com
http://sqlblog.com/blogs/denis_gobo/default.aspx

On Nov 28, 8:26 am, sanjeev.atvan...@gmail.com wrote:
> Dear Gurus,
>
[quoted text clipped - 41 lines]
> Sanjeev
> sanjeev.atvan...@gmail.com
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.