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 2000 Forums
 SQL Server Development (2000)
 how to implement top function with sql query

Author  Topic 

ldbl
Starting Member

3 Posts

Posted - 2005-06-22 : 08:59:17
can anybody help me how to make query that can replace
TOP command of MS SQL server .

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-06-22 : 09:03:03
Look for RowCount in Books On Line

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

ldbl
Starting Member

3 Posts

Posted - 2005-06-22 : 09:47:44
it's not very importand to me to set numbers of rows to output
it's enought only to get 1 row with most repeated record in the database
i'm stick here to get maximum with all data
select * from (select #1057;#1090;#1086;#1082;#1072;#1048;#1044;,max(cnt)as maximum,DIN from (select n.#1057;#1090;#1086;#1082;#1072;#1048;#1044;,s.DIN,count(*) as cnt from #1090;#1073;#1053;#1072;#1083;#1080;#1095;#1085;#1086;#1089;#1090; as n
JOIN #1090;#1073;#1057;#1090;#1086;#1082;#1080; as s ON n.#1057;#1090;#1086;#1082;#1072;#1048;#1044; = s.#1057;#1090;#1086;#1082;#1072;#1048;#1044;
GROUP BY n.#1057;#1090;#1086;#1082;#1072;#1048;#1044;,s.DIN) as s
GROUP BY cnt,#1057;#1090;#1086;#1082;#1072;#1048;#1044;,DIN) as b
ORDER BY maximum DESC
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-06-22 : 10:15:45
What do you want to get from that?
If you want to get most repeated value, you need to use Count
See BOL for more info


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2005-06-23 : 04:49:26
you're in the right direction using group by
include the having clause: having count(*)>1 before the order by

am not sure of your query, got confused with the #s and ;

HTH though

--------------------
keeping it simple...
Go to Top of Page

ldbl
Starting Member

3 Posts

Posted - 2005-06-23 : 08:24:36
here is from here i want to get max count.

select * from (select count(*) as cnt ,s.din from Store as t1
JOIN Stock as t2 ON t2.StockID = t1.StockID
GROUP BY s.din ) as t3
ORDER BY t3.cnt DESC

Go to Top of Page
   

- Advertisement -