I have a statement like this:
UPDATE `MyTable`
SET point = point + 1
WHERE (mySubject = 'MATHEMATICS' AND myGrade = '100') OR
(mySubject = 'PHYSICS' AND myGrade = '75') OR
(mySubject = 'PHYSICS' AND myGrade = '75')
And I want the table to be updated to:
MATHEMATICS | 100 | 1
PHYSICS | 75 | 2
instead of
PHYSICS | 75 | 1
The reason why there is a duplicated ‘PHYSICS’ condition is because I get this information from another function.
And I want to know if I can increment PHYSICS point by two if the other function pass me PHYSICS 2 time.
Is there a way to do this in one connection instead of calling the UPDATE 3 times :
UPDATE `MyTable` SET point = point + 1 WHERE mySubject = 'MATHEMATICS' AND myGrade = '100'
UPDATE `MyTable` SET point = point + 1 WHERE mySubject = 'PHYSICS' AND myGrade = '75'
UPDATE `MyTable` SET point = point + 1 WHERE mySubject = 'PHYSICS' AND myGrade = '75'
When you make UPDATE to table it takes each row ONCE ONLY..
So it wont generate 2 updates for the Physics…
This query say’s to the SQL ..
UPDATE for me all rows in MyTable WHERE (case a) or (case b) or (case c)
SQL takes Mathematics and at case a its OK and updated.
Then it takes Physics and at case b they are OK and updated and then sql FINISH because there no more ROWS at table..
You have to make 2 seperated updates to do your job..
Or you can use CASE