On Fri, Jul 18, 2008 at 3:46 PM, Rob Wultsch <[EMAIL PROTECTED]> wrote:
> I'm sure there is a way to write this in a single query, but I bet it
> it is ugly as heck, probably with a bunch of derived tables.

INSERT INTO balances (userid, points)
SELECT users.userid, users.points
FROM users
LEFT JOIN (
        SELECT userid, MAX(timestamp_dump) AS 'timestamp_dump'
        FROM balances
        GROUP BY userid
        ) AS b1 USING(userid)
LEFT JOIN balances b2 USING(userid,timestamp_dump)
WHERE users.points != b2.points
        OR b2.points IS NULL ;

This query is a dog, That stored procedure is pretty horrible. I'm
going to play with trying to figure out how to optimize this. Fun
stuff.


-- 
Rob Wultsch

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

Reply via email to