Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Constrain result set by unique code in query.
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

1 Posts

Posted - 07/08/2013 :  21:28:47  Show Profile  Reply with Quote
Hi to this. Pls be gentle.

Q. If I have a simple query like:

select * from bigtable
where product_code in ('abc','def','hij','klm')

I know that each of those product_codes will return a large data set. What I'd like to do is to run the same query but constrain the result set to a max rownum of 200.

Is this possible?

Thanks in advance...

Aged Yak Warrior

549 Posts

Posted - 07/09/2013 :  00:48:51  Show Profile  Reply with Quote
Try this:

(select ROW_NUMBER() OVER(PARTITION BY product_code order by product_code) AS RN, * from bigtable
where product_code in ('abc','def','hij','klm')) A
WHERE RN <= 200;
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000