Nikunj Satasiya

Nikunj Satasiya

  • 183
  • 10k
  • 3.6m

How to Use Order BY Without Group By in Sql Server

Jul 26 2018 4:25 AM
Hello Everyone,
 
Can anyone know how to use order by without use of group by ?
 
Problem :
 
I have some of col in my sql query of select like where i also used some aggregate functions now i want to use one col EntryDate from my table but didn't want to use that in group by.
 
Example:
  1. SELECT ID,  CONVERT(VARCHAR(15), EntryDate, 101) AS Entry_Date , NAMESUM(PRICE) FROm MYTABLE WITH ( NOLOCK ) GROUP BY ID, NAMECONVERT(VARCHAR(15), EntryDate, 101)   
But I Want Something like this without use Group By
  1. SELECT ID,  CONVERT(VARCHAR(15), EntryDate, 101) AS Entry_Date , NAMESUM(PRICE) FROm MYTABLE WITH ( NOLOCK ) GROUP BY ID, NAMECONVERT(VARCHAR(15), EntryDate, 101)   
  2. ORDER BY EntryDate  
 Can Anyone Help me Please ?

Answers (10)