|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
select Top 3
SELECT Country, CatDescription FROM VIEW1 WHERE (Country IN ('hong kong', 'LA')) GROUP BY Country, CatDescription ORDER BY Country Country Category --------------------------------------- Hong Kong Point of Purchase Hong Kong Literature Hong Kong Advertisement Hong Kong Gifts Premium LA Gifts Premium LA Advertisement LA Seminar Kit LA Literature LA Point of Purchase How to select Top 3 from the View 1 to get the result below? Country Category --------------------------------------- Hong Kong Point of Purchase Hong Kong Literature Hong Kong Advertisement Hong Kong Gifts Premium LA Gifts Premium LA Advertisement LA Seminar Kit thanks. |
|
#2
|
|||
|
|||
|
May be you must create stored procedure to get result. I Think don't use view, in my experience in ERP Development, if we use view, query may be in the lock position in the server because we must load all data first before filtering.
Regards Tonny |
|
#3
|
||||
|
||||
|
Quote:
no such thing exists in SQL Server PHP Code:
|
|
#4
|
|||
|
|||
|
SELECT TOP 3 Country, CatDescription
FROM VIEW1 WHERE Country = 'hong kong' GROUP BY Country, CatDescription ORDER BY Country UNION SELECT TOP 3 Country, CatDescription FROM VIEW1 WHERE Country = 'LA' GROUP BY Country, CatDescription ORDER BY Country I think that is no smart solution, how do you know that country only exist 'hongkong' and 'la' value? Why we must hard code the where condition? How about using parameter? may be this is more rasionable. |
|
#5
|
||||
|
||||
|
his previous question (http://forums.aspfree.com/t33428/s.html) makes me asume he's calling it from code somewhere , and i just gave him an example of how to do it, the smart person can take it from there
|
|
#6
|
|||
|
|||
|
passing variable
the country is passed as the coundition. so, I can select might be more than 3 country.
Union is not really solving it right? any good suggestion? |
|
#7
|
||||
|
||||
|
unions are not limited to 2 selects, you can do
PHP Code:
here is an alternative (i used ID for the primary key), but it's not much better: PHP Code:
|
![]() |
| Viewing: ASP Free Forums > Database > Microsoft SQL Server > select Top 3 |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|