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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to get 3 items per company

Author  Topic 

homedev
Starting Member

2 Posts

Posted - 2011-07-02 : 11:00:26
It is a website with about 400 affiliates. On a page with recent items I need to get the last 3 items uploaded PER affiliate.
I have a query that gets all items but I don't know how to get 3 items per affiiate. If I use TOP 3 it ony returns 3 rows


SELECT TOP 1200 T_items_title,
T_items_itemid as itemid,
T_items_partnerID,
T_partners_companyname as companyname,
dbo.T_partners.T_partners_foldername as folder,
T_partners_website as website

FROM dbo.T_items INNER JOIN
dbo.T_partners ON dbo.T_items.T_items_partnerID = dbo.T_partners.T_partners_id
WHERE (dbo.T_partners.T_partners_typepartner = 1) AND (dbo.T_items.T_items_active = 1)
ORDER BY T_items_itemid desc

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2011-07-02 : 11:05:41
SQL 2005 or above?

--
Gail Shaw
SQL Server MVP
Go to Top of Page

homedev
Starting Member

2 Posts

Posted - 2011-07-02 : 16:17:50
it is SQL 2008

Bianca
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2011-07-02 : 17:43:28
What column is the affiliate?
Is the itemid an identity? Is there a datetime column that stores the time inserted for an item?

--
Gail Shaw
SQL Server MVP
Go to Top of Page
   

- Advertisement -