Reputation: 51
I want to insert data into department column because it only has Null values so I created Variable called $department grabbing correct data but I don't want to affected the other columns they already have correct data.
users
UserID , first name , last name , department
right now not sure what am doing wrong. this is what i have tried.
UPDATE Users SET department= '$department'";
INSERT INTO Users (department) VALUES ('$department');
thanks!
Upvotes: 1
Views: 279
Reputation:
UPDATE Users SET department = '$department' WHERE department IS NULL;
This query put your correct value on each record that department field is null.
Upvotes: 0
Reputation: 222512
but I don't want to affected the other columns they already have correct data.
So filter out the rows you don't want to update:
UPDATE Users SET department= '$department'" WHERE department IS NOT NULL;
Upvotes: 1