• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

simple Update fail

 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
could anyone advise why this doesn't work and what should be the correct sql?

UPDATE QA SET T_ID=48 WHERE QA_ID = (SELECT MAX(QA_ID) FROM QA WHERE Q_ID = '11' GROUP BY Q_ID)

the statments:
UPDATE QA SET T_ID=48 WHERE QA_ID = 1500
and
SELECT MAX(QA_ID) FROM QA WHERE Q_ID = '8871' GROUP BY Q_ID //returns 1500

works fine!

thanks
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34645
363
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter,
What database are you using? Do you get an error message or does it just not update.

This may just be a typo, but the first example uses q_id = 11 and the second uses 8871.
 
Scott Johnson
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the exception/error message?

In some databases (i.e., Informix), you can't do a subselect from the same table that you are updating.
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the err msg is:
ERROR 1064: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT

I'm using mySQL.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34645
363
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter,
It looks like a bug in MySql.

Take a look at the comments below the manual. Search that page for "February 16 2005" and then read the next few posts.
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mmmmm...well the problem is on a linux server having mysql 4.0.24

(it works on windows with mysql 5.0.22)

do you think upgrading to 5.0.22 on the linux machine will solve the problem?

thanks
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34645
363
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't encountered this problem myself. You might want to check the detailed mySql release notes to see when they fixed it.
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a workaround you could rewrite the query as a join and see if that works.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic