Group function not working on SQL server -


i use below query, shows repeated items. use group function, not work.

select p.productid, p.productname, p.catid, p.subcatid, p.producttype,        p.modelno, p.picurl, p.color, p.theme, p.productprice, p.discountedprice,        p.quantity, p.details, p.mainpagedisplay, p.productpagedisplay,        s.subcatid expr1,        s.subcatname, s.catid expr2,        s.rank, s.subcatname expr3 (products p inner join       subcategories s on p.catid = s.catid) (p.color = 'red') group p.productname 

this query working fine, when add group by it's not working.

you don't need group by selecting distinct rows, need distinct:

select distinct p.productid, p.productname, p.catid, p.subcatid, p.producttype,        p.modelno, p.picurl, p.color, p.theme, p.productprice, p.discountedprice,        p.quantity, p.details, p.mainpagedisplay, p.productpagedisplay,        s.subcatid expr1,        s.subcatname, s.catid expr2,        s.rank, s.subcatname expr3 (products p inner join       subcategories s on p.catid = s.catid) (p.color = 'red') 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -