[SOLVED] SQL Update Syntax

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Kingo
Forum Contributor
Posts: 146
Joined: Thu Jun 03, 2004 9:38 am

[SOLVED] SQL Update Syntax

Post by Kingo »

Hello,
I'm trying to update a table in MYSQL with three conditions. I dont know where i'm going wrong. Any help is appreciated.
Here is the code

Code: Select all

update data1 set value='98' where Subject='English', Type='School Score' and Year='01-02';
My table has 5 coulms. I want to update the column "Value" based on three columns " Subject", "Type", and "Year".
lostboy
Forum Contributor
Posts: 329
Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada

Post by lostboy »

missing an AND

Code: Select all

update data1 set value='98' where Subject='English' AND Type='School Score' and Year='01-02';p
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Code: Select all

UPDATE data1 SET value='98' WHERE Subject='English' AND Type='School Score' AND Year='01-02';
With cases like this try using SQL directly and see what error messages come out. For this problem a bit of homework as follows would have shown your problem...

Code: Select all

UPDATE data1 SET value='98' WHERE Subject='English';
Works... Next

Code: Select all

UPDATE data1 SET value='98' WHERE Subject='English', Type='School Score';
Doesn't work... What am I doing wrong? Check the syntax from manual... Oh that's obvious.
:wink:
Kingo
Forum Contributor
Posts: 146
Joined: Thu Jun 03, 2004 9:38 am

Post by Kingo »

Thanx very much . It works with another AND
Post Reply