sqlmysqlinsert

How to INSERT 6 VALUES simultaneously in column named salary in Table named employees TABLE has 6 employee ids in emp_id column


I have these values(mentioned BELOW) which i'm trying to insert in (newly made) salary column of employees table. Salary column is INT NOT NULL DEFAULT 25000. 37000, 32000, 35000, 45000, 55000, 37000.

I have got these values for emp_id column which are already there 101, 102, 103, 104, 105, 106

I've tried these syntax

INSERT INTO employees(Salary)
 VALUES (37000), (32000), (35000), (45000), (55000), (37000);

and

ALTER table employees INSERT INTO Salary VALUES (37000, 32000, 35000, 45000, 55000, 37000);

and many more but won't embarrass myself more xD

[TABLE employees looks like this on display as of now]


Solution

  • Use UPDATE to modify the contents of existing rows. Use CASE to specify the value for each employee ID.

    UPDATE employees
    SET Salary = CASE emp_id
        WHEN 101 THEN 37000
        WHEN 102 THEN 32000
        WHEN 103 THEN 35000
        -- and so on for all employee IDs
        ELSE Salary -- leave unchanged if not in the above list
    END