Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 GROUP BY problem

Author  Topic 

djp
Starting Member

1 Post

Posted - 2008-06-02 : 13:34:37

SELECT *
FROM table
WHERE strict_name = 'ThisField'
GROUP BY strict_name
ORDER BY n_data DESC


I have more then 1 lines for strict_name = 'ThisField' ranging from (primary key) 49 to 54

with the SQL i show you what I aim to get is to get one line with the first primary key (49) and for some reason i get number 51

:|

Can someone explain to me why?
And help me !

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-02 : 13:41:48
You are GROUPING by strict_name. So it will be returning only one row per strict_name. Then you are filtering by strict_name = 'ThisField'. So it will only a single row having strict_name = 'ThisField'. The rest values depend on what aggregate function you apply on other fields. Since you're getting pk as 49 i think you're returning MIN(PK)
Go to Top of Page
   

- Advertisement -