0

I have the following:

SELECT * FROM (SELECT * FROM table ORDER BY id DESC) t GROUP BY pcid

SELECT * FROM (SELECT * FROM table ORDER BY timestamp DESC) t GROUP BY pcid

I am unable to get the GROUP BY to be in the correct order. It always pulls from the lowest value.

Am I missing some syntax that is oblivious to me?

After looking for the past several hours to find a solution to this issue, I have been unable to resolve. This question has been asked because I have been unable to find the answer.

Here is my table structure:

table id,primary pcid cpu memphy memcom memvir timestamp

I have tried sorting by timestamp and id with no luck.

2 Answers2

0

You should give more detail but it might be something like this :

 SELECT column, highest, count(somecolumnname)
 FROM table_name 
 GROUP BY column, highest 
 ORDER BY highest DESC
Hamza Zafeer
  • 2,360
  • 13
  • 30
  • 42
Ufuk Ugur
  • 186
  • 1
  • 17
0

This query should return the rows that you need:

select
  t.*
from
  table t INNER JOIN (select column, max(highest) m_highest
                      from table
                      grouo by column) tm
  on t.column=tm.column and t.highest=tm.m_highest

The subquery will return the maximum highest per column, then you join back to the original table t and return all rows that have highest=the maximum highest per column.

fthiella
  • 48,073
  • 15
  • 90
  • 106