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
 I need Maximum value (STRING)

Author  Topic 

Easwar
Yak Posting Veteran

59 Posts

Posted - 2007-03-14 : 01:38:42

Ex Table
-----------------
ColName====> Field Name
------------
xyz
abc
xyz
abc
abc
sdf
abc
....
....
---------

In table column string. i need maximum ColName.. In above table maximum ColName is abc... also top 3 maximum ColName i need...
Result
------
abc

How to i'll get any query........
Top 3 Maximum Result
--------------------
abc
xyz
sdf
----------------------------
this also.......

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-03-14 : 01:48:37
select top 3 distinct colname from table1 order by colname desc


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

Easwar
Yak Posting Veteran

59 Posts

Posted - 2007-03-14 : 01:54:36


select top 3 distinct colname from table1 order by colname desc

This query Not worked

Error will appear

Error
-------
Incorrect syntax near the keyword 'distinct'.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-03-14 : 01:58:04
Ooops!

select distinct top 3 colname from table1 order by colname desc

Peter Larsson
Helsingborg, Sweden
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-14 : 01:58:09
[code]
select top 3 colname from table1 group by colname order by colname desc
[/code]


KH

Go to Top of Page

Easwar
Yak Posting Veteran

59 Posts

Posted - 2007-03-14 : 02:12:31
select distinct top 3 colname from table1 order by colname desc

select top 3 colname from table1 group by colname order by colname desc

Above two query same result..

But not correct result.........
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-14 : 02:17:17
Sorry


select top 3 colname from table1 group by colname order by colname count(*) desc




KH

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-14 : 02:18:09
Must have left my brain at home today


KH

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-03-14 : 02:22:46
Well, OP was not that clear either...


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-14 : 02:32:11
quote:
Originally posted by Peso

Well, OP was not that clear either...


Peter Larsson
Helsingborg, Sweden



OK. Blame it on the OP . Anyway, i am at home now. Found my brain right where i left it


KH

Go to Top of Page

Easwar
Yak Posting Veteran

59 Posts

Posted - 2007-03-14 : 02:38:29
Thanks very much...........

select top 3 colname from table1 group by colname order by count(*) desc

this query now worked............
Go to Top of Page
   

- Advertisement -