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.
| Author |
Topic |
|
kpreston
Starting Member
2 Posts |
Posted - 2004-10-28 : 12:29:09
|
| I am trying to rewrite a select statement using the TOP clause for SQL. Right now we return a bulk set of data and then use VFP 8.0 to take out the necessary data. I was able to get the TOP to work (sort of). I need to be able to get the top 5 records for products purchased on, purchased off, and purchased froma different contract (three types). In a nutshell I need the top x records for type 1,2,and 3 (15 total records) and when I use the TOP clause I get only 5 total records. Any ideas?Thanks in advanceKelly |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-10-28 : 12:33:50
|
use union. number and type of coulmns must be same for all select used in union.select *from(select top 5 ... -- purchased onfrom Table1union allselect top 5 ... -- purchased offfrom Table1union allselect top 5 ... -- purchased fromfrom Table1) t1Go with the flow & have fun! Else fight the flow |
 |
|
|
kpreston
Starting Member
2 Posts |
Posted - 2004-10-28 : 13:49:44
|
| When I tried the union piece I am getting a different total of units sold when I run the whole union clause versus just running one branch of the select statement. And the order is not showing the correct order with the union piece of the statment. Any ideas?kelly |
 |
|
|
|
|
|