Jaymond Flurrie
Well-known Member
- Joined
- Sep 22, 2008
- Messages
- 921
- Office Version
- 365
- Platform
- Windows
Should be an easy question: If I want top 100000 records and the source happens to have only, say, 100 records, do I need to check something or is SQL smart enough to understand that it takes smaller of these two (either that top ( = 100000) or then everything (= 100))?
The idea is that I want no more than 100000 records as the result and if the source happens to have more, I pull out just a sample of 100000 and I thought to use "SELECT TOP 100000 * FROM customers ORDER BY NEWID()" to accomplish this. Can you spot any possible problems with this?
edit. Another question to continue this a bit is that can I order them by CustomerID as well? I mean, let's say I have only five customers there and I execute the "NEWID"-lottery, getting the table like
1 5
2 3
3 4
4 2
5 1
where on left is CustomerID and on right is the NEWID. I get as the result 5,4,2 and I would like to have them as 2,4,5. What's the smartest way to rearrange them?
The idea is that I want no more than 100000 records as the result and if the source happens to have more, I pull out just a sample of 100000 and I thought to use "SELECT TOP 100000 * FROM customers ORDER BY NEWID()" to accomplish this. Can you spot any possible problems with this?
edit. Another question to continue this a bit is that can I order them by CustomerID as well? I mean, let's say I have only five customers there and I execute the "NEWID"-lottery, getting the table like
1 5
2 3
3 4
4 2
5 1
where on left is CustomerID and on right is the NEWID. I get as the result 5,4,2 and I would like to have them as 2,4,5. What's the smartest way to rearrange them?
Last edited: