I just thought of something else... could the same be accomplished using stored routines? I could find no way in MySQL to create stored routines which could be used with the 'group by' queries though.

If this were possible, it should then be also possible to define a 'LAST' stored routine, or something which would output a given field value based on whether some other field (say, numeric ID, or timestamp) was the highest in its group.

This looks to be possible with external functions ('CREATE AGGREGATE FUNCTION'), but this would require writing an external library to handle the call, too. It would be strange it if were impossible to create an aggregate stored procedure.

        Does anyone know if it's possible to define stored procedures this way?

Rob Wultsch wrote:
On Fri, Apr 11, 2008 at 1:01 PM, Victor Danilchenko
<[EMAIL PROTECTED]> wrote:
        Oooh, this looks evil. It seems like such a simple thing. I guess
creating max(log_date) as a field, and then joining on it, is a solution --
but my actual query (not the abridged version) is already half a page long.

        I think at this point, unless someone else suggests a better
solution, this would be easier to do programatically -- skip the group
altogether, and instead simply order the rows, and grab the last one for
each username in code.

        I guess another alternative would be to use a View for the UNIONized
query, but doesn't MySQL 'fake' views in 5.0 somehow?

I have used views to good results, however I have read not good things
about them. I would not be surprised if they worked well for this use.

I would also not be surprised if the merge storage engine was a better
option for you.

Possibly interesting:
http://www.mysqlperformanceblog.com/2007/08/12/mysql-view-as-performance-troublemaker/



--
        Victor Danilchenko
        Senior Software Engineer, AskOnline.net
        [EMAIL PROTECTED] - 617-273-0119

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to