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
 Constrain result set by unique code in query.

Author  Topic 

shimarli
Starting Member

1 Post

Posted - 2013-07-08 : 21:28:47
Hi there..new 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...

MuMu88
Aged Yak Warrior

549 Posts

Posted - 2013-07-09 : 00:48:51
Try this:
[CODE]
SELECT * FROM
(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;
[/CODE]
Go to Top of Page
   

- Advertisement -