MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 20th, 2004, 03:44 AM
desember desember is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 15 desember User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Limit in mysql = top in sql server ?

I have used this mysql code in my programm before:

select * from address order by vorname asc limit 0, 10

It works fine. But now I want to use sql server, and it doesn't recognize the term limit.
So I have found out that I can use top instead.
I have changed my code into this:

select top 0 * from (select top 10* from address order by vorname) order by vorname asc

But it gives me an error message:

wrong syntax near the word Order.

Can anyone give me a solution?
Thank you.

Reply With Quote
  #2  
Old July 20th, 2004, 03:00 PM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 1,773 swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 14 h 9 m 36 sec
Reputation Power: 37
Why complicate matters?

Code:
select top 10* from address order by vorname

Reply With Quote
  #3  
Old July 21st, 2004, 05:05 AM
desember desember is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 15 desember User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Sorry, my mistake
it works fine if the limit is 0,10
but what if the limit is 10,10 ?

Thank you

Reply With Quote
  #4  
Old July 21st, 2004, 10:08 AM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 1,773 swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 14 h 9 m 36 sec
Reputation Power: 37
Code:
select top 10 * from address 
where vorname not in (select top 10 vorname 
from adress 
order by vorname)
order by vorname

Reply With Quote
  #5  
Old November 23rd, 2004, 06:19 AM
captainkeeken captainkeeken is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 1 captainkeeken User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Problem with sorting

Quote:
Originally Posted by swampBoogie
Code:
select top 10 * from address 
where vorname not in (select top 10 vorname 
from adress 
order by vorname)
order by vorname


I'm afraid this won't really help.

look at this example :

id |val
---+---
1 | aa
2 | aa
3 | bb
4 | bb

"SELECT * ORDER BY val ASC"

will return

1,aa
2,aa
3,bb
4,bb

"SELECT * ORDER BY val DESC"

will return

3,bb
4,bb
1,aa
2,aa

Vou see, this isn't what we would expect under MySQL.
MSSQL doesn't actually reverse the recordset with your approach.

Reply With Quote
  #6  
Old November 23rd, 2004, 06:50 AM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 1,773 swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 14 h 9 m 36 sec
Reputation Power: 37
Quote:
MSSQL doesn't actually reverse the recordset with your approach.


What recordset? There is no order to reverse. If you order by a column which have duplicates you can't predict anything about the order within the group.

To get the order

id val
-----
4 bb
3 bb
2 aa
1 aa

you must use

Code:
order by val desc,id desc

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Limit in mysql = top in sql server ?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway