sql - Creating a stored procedure with many-to-many relationship giving proper response -
i'm trying create stored procedure school project uses model first. wanted make sp returning av list of games orders, 'top list' speak, can't figure out after searching similiar threads. parameter @antal should return range of distinct results give back. let's send in 5 should return 5 products, , 3 should return 3 products , forth...
since new this, i'm stuck. code far is:
use spelaffarendatabas go create procedure [dbo].[gettoplistgames] ( @antal int ) select distinct top (6) p.id, p.name, p.orders, k.name, g.name produktset p left join consoleproduct kp on p.id = kp.product_id left join consoleset k on kp.console_id = k.id left join productgenre pg on p.id = pg.product_id left join genreset g on pg.genre_id = g.id group p.id, p.name, p.orders, k.name, g.name
so how go getting proper response gives me proper response, whic guess of distinct entities?
select distinct top (@antal) p.id, p.name, p.orders, k.name, g.name produktset p left join consoleproduct kp on p.id = kp.product_id left join consoleset k on kp.console_id = k.id left join productgenre pg on p.id = pg.product_id left join genreset g on pg.genre_id = g.id group p.id, p.name, p.orders, k.name, g.name order p.orders desc
Comments
Post a Comment