Ed Leafe wrote: > On Sep 2, 2007, at 7:58 PM, Ricardo Aráoz wrote: > >> select EmployeeId, EmpName, sum(salary) ; >> from Employee ; >> group by EmployeeId >> >> This would have sense but it is easily done with : > > To a human, perhaps, but to a database engine, there is no > constraint that the ID and name be a 1:1 pair. > >> select EmployeeId, max(EmpName) as 'EmpName', sum(salary) ; >> from Employee ; >> group by EmployeeId > > And why is is that any simpler (or better, or cleaner, or...) than: > > select EmployeeId, EmpName, sum(salary) ; > from Employee ; > group by EmployeeId, EmpName > > If I inherited code that used max() of a name, red flags would be > raised in my mind as to the original coder's sanity. ;-) > >
True, and besides the table would not be normalized wouldn't it? Maybe not the best of examples. Out of memory I could say that when you have 10 or 20 fields in your output but the group by is by 4 or 5 of them, then using max() will give you more readable code (Not my tables, inherited from a legacy system) as the REAL grouping variables will be there instead of 10 or 20 vars which could cloud the issue. _______________________________________________ Post Messages to: ProFox@leafe.com Subscription Maintenance: http://leafe.com/mailman/listinfo/profox OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED] ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.