Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to update a table, say Table 1 using a table that I create on the fly (saytemp). To achieve this I have the following query:

UPDATE Table1 SET COUNT = temp.ctemp FROM ( SELECT A, SUM(UNO) AS ctemp FROM Table1
                                            GROUP BY A 
                                            ORDER BY A) 
                                      AS temp,Table1 t1
                                      WHERE temp.A = t1.A;

It works well in SQL Server 2008 but MySQL throws out the error

syntax error, unexpected FROM, expecting 'END_OF_INPUT' or ';'

Any idea what I am missing here?

share|improve this question
up vote 1 down vote accepted

UPDATE syntax in MySQL is different than SQL-Server. This will do:

UPDATE Table1 AS t
      ( SELECT A, SUM(UNO) AS ctemp 
        FROM Table1
        GROUP BY A                     -- no need for `ORDER BY` in either DBMS
      ) AS temp
    ON temp.A = t.A  
    t.COUNT = temp.ctemp ;
share|improve this answer
The query worked. I had the ORDER BY in there to verify just the query - you were right to note that it was not needed. – sriramn Mar 31 '13 at 23:12

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.