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 |
|
ckuo@kahluadesigns.com
Yak Posting Veteran
58 Posts |
Posted - 2003-11-24 : 17:00:39
|
| Hi,Say I haveSELECT ProductID, Price FROM Table1 WHERE CategoryID = 10UNIONSELECT ProductID, Price FROM Table2 WHERE CategoryID = 10How do I specify a TOP 20 of both statments or after the union. Problem I am having is that when I sort this by Price, I get results of rows before the union. I just want to sort within these two statements. Thanks. |
|
|
chadmat
The Chadinator
1974 Posts |
Posted - 2003-11-24 : 17:41:11
|
| select top 20 ...FROM (SELECT ProductID, Price FROM Table1 WHERE CategoryID = 10UNIONSELECT ProductID, Price FROM Table2 WHERE CategoryID = 10) aorder by Price asc-Chadhttp://www.clrsoft.comSoftware built for the Common Language Runtime. |
 |
|
|
Granick
Starting Member
46 Posts |
Posted - 2003-11-24 : 18:13:45
|
| It is really funny. I was going to suggest this exact idea, but when I did a quick test on some of my own data tables, I got an error, so I didn't. I went ahead and set up trial similar to what is happening here, it worked. Very weird.Shannon |
 |
|
|
mohdowais
Sheikh of Yak Knowledge
1456 Posts |
Posted - 2003-11-25 : 01:58:40
|
>>It is really funny. I was going to suggest this exact idea, but when I did a quick test on some of my own data tables, I got an error, so I didn't. I went ahead and set up trial similar to what is happening here, it worked. I bet you forgot the alias for the subquery.Owais Please excuse my driving, I am reloading. |
 |
|
|
|
|
|
|
|