The functions MAX
, MIN
, etc. use the lexicographic order when applied to text columns. Therefore, your MAX(type) will return ‘Printer’ instead of ‘PC’ because ‘Printer’ is after (greater than) ‘PC’ in alphabetic order.
Notice that in your first query the condition HAVING COUNT(distinct type) = 1
means that there can only be a single type
value for each group. The MAX(type)
clause in the select is used because simply type
can not be used in the select as it is not in the GROUP BY
clause.