SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Aug 2004
    Location
    Utah, USA
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    subquery question

    MySQL 5 is throwing an error when I try to use this query:

    UPDATE userpoints_summary up
    (
    SELECT uid, SUM(points) AS lp
    FROM userpoints_txn
    WHERE status = 0 AND points > 0
    GROUP BY uid
    ) q
    SET up.lifetime_points = lp
    WHERE q.uid = up.uid

    Can anyone see where I've messed up?

    TIA,
    Kevin

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,216
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    you forgot the comma

    but you mought as well use JOIN syntax (yes, i wrote "mought")
    Code:
    UPDATE userpoints_summary AS up
    INNER
      JOIN (
           SELECT uid, SUM(points) AS lp
           FROM userpoints_txn
           WHERE status = 0 AND points > 0
           GROUP BY uid
           ) AS q
        ON q.uid = up.uid
       SET up.lifetime_points = q.lp
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Zealot
    Join Date
    Aug 2004
    Location
    Utah, USA
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks so much.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •