Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

Get 2 products from each group

$
0
0

Hi,

I'm trying to write some SQL that will get me 2 of each product from each group.

We have 65 groups in table1 (if relevant), and the 40000 products in table2.

I can't work out how I need to write the code to achieve this. In total we should get 130 products from our 40000.

EG

Product table

Text
ProdName | GRP |col3 | col4 Product 1 | Group 1 | info... | more info.... Product 2 | Group 1 | info... | more info... Product 3 | Group 1 | info... | more info... Product 4 | Group 2 | info... | more info... Product 5 | Group 2 | info... | more info... Product 6 | Group 2 | info... | more info... 

Output should be

Text
ProdName | GRP | col3 | col4 Product 1 | Group 1 | info... | more info.... Product 2 | Group 1 | info... | more info... Product 4 | Group 2 | info... | more info... Product 5 | Group 2 | info... | more info... 
Thanks,

Bryn


Viewing all articles
Browse latest Browse all 4871

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>