Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Hi, I have a table with records of people who signed up for a waitlist to purchase one or more of several products. I'd like to be able to return a result set with the first n users who added themselves to the waitlist for specific products so I can contact them as the products become available. For example, I have the following table which I use to record their preferences:
Of course I know the easy part, which is selecting just for the specific products like this:SELECT *FROM WaitlistMembersWHERE ProductID IN (3,5)I can't figure out how to only get the first two signups (by SignupTime) for each product. Any help is greatly appreciated!
fishpop
Starting Member
2 Posts
Posted - 2009-09-20 : 02:44:50
Well, in case anyone stumbles upon this thread, here's how I accomplished it:
SELECT *FROM (SELECT WaitlistMemberID, UserID, ProductID, SignupTime, ROW_NUMBER() OVER( PARTITION BY ProductID ORDER BY SignupTime ) rnFROM WaitlistMembersWHERE ProductID IN (3,5)) derivedWHERE rn <= 2