Click here to Skip to main content
15,905,558 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
SQL
SELECT prl.description ,
               DISTINCT
convert(varchar,prl.effective_date,103) effective_date,
    b.description brand  ,
     pc.description cat 
     FROM ProductRateList prl,Products pro,ProductCatg pc, Brands b  
     WHERE pro.Id = prl.Product_Id AND pc.Id = pro.ProdCatg_Id  AND B.Id = pro.Brand_id  AND pro.Active = 'Y' 
     order by prl.effective_date desc, 
     PRl.description ASC 
     group by convert(varchar,prl.effective_date,103),prl.description
Posted
Updated 20-Feb-12 2:05am
v2
Comments
Om Prakash Pant 17-Feb-12 5:39am    
what result you are getting?
you should get distinct records on prl.description ,convert(varchar,prl.effective_date,103) effective_date, b.description brand , pc.description cat
Photon_ 17-Feb-12 7:02am    
this should be right query


SELECT DISTINCT prl.description ,
convert(varchar,prl.effective_date,103) effective_date,
b.description brand ,
pc.description cat
FROM ProductRateList prl,Products pro,ProductCatg pc, Brands b
WHERE pro.Id = prl.Product_Id AND pc.Id = pro.ProdCatg_Id AND B.Id = pro.Brand_id AND pro.Active = 'Y'

1 solution

And this could be used as exact solution which will have the order by and as well as the group by function too
SQL
SELECT DISTINCT  prl.description ,
   convert(varchar,prl.effective_date,103) effective_date,
  b.description brand  ,
   pc.description cat
   FROM ProductRateList prl,Products pro,ProductCatg pc, Brands b
   WHERE pro.Id = prl.Product_Id AND pc.Id = pro.ProdCatg_Id  AND B.Id = pro.Brand_id  AND pro.Active = 'Y'
    group by convert(varchar,prl.effective_date,103),prl.description , b.description   ,
   pc.description
   ORDER BY prl.Description

order by can contain only those column who either have aggregate function or have distinct
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900