|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
DISTINCT sql Problem
Dear All,
I have a query where I want to select the top 3 portfolio Items, however these must have distinct Category names. Here is the SQL which I came up with, however it is not working:- SELECT TOP 3 portfolio.*,DISTINCT [category].[CatName] FROM portfolio INNER JOIN category ON [portfolio].[catID]=[category].[catID] ORDER BY CatName ASC, portfolioID DESC" Can you please help me out. Thanks |
|
#2
|
||||
|
||||
|
Code:
select top 3
portfolio.*
, [category].[catname]
from portfolio
inner
join category
on [portfolio].[catid]=[category].[catid]
where portfolioid in
( select min(portfolioid)
from portfolio
group
by catid )
order
by catname asc
, portfolioid desc
then the main query gets all those portfolios, thus only one per category then the TOP keyword ensures you get only three of them rudy http://r937.com/ |
![]() |
| Viewing: Dev Shed Forums > Databases > Database Management > DISTINCT sql Problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|