I have the a postgre sql query as follows
SELECT cNo,max(numLogs),name,surname FROM details GROUP BY cNo,name,surname
and if I run this my results don’t group cNo instead, is there any way I can get the cNo unique/grouped.
I get the results similar to the following
cNo numLogs name surname
23 43 asfas safdasd
23 45 dsfds fdsfsdfsd
23 43 dsfsd dsfsdfsd
and I want something like
cNo numLogs name surname
23 45 asfas safdasd
If you only want the unique
cNo‘s and you don’t care about which name / surname you are pulling you can use another aggregate function on those fields.Otherwise, what you are pulling is each unique combination of
cNo,name, andsurname.If you need to pull a particular name or surname (that won’t be pulled by
min,maxor any of PostGreSQL’s aggregate functions), then you’ll want to filter your results rather than selecting everything from the table.