Take the 2-minute tour ×
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. It's 100% free, no registration required.

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
add comment

1 Answer 1

up vote 1 down vote accepted

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

UPDATE Table1 AS t
  JOIN
      ( 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  
SET 
    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. –  RazorXsr Mar 31 '13 at 23:12
add comment

Your Answer

 
discard

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.