Update records of one table using data from another table

Raghav

I've two tables.

Table 1: Employees

EID Name    Gender
1   Peter   M
2   John    M
3   Melissa F

Table 2: Salary

EID Salary
1   6000
2   8000
3   10000

I need to raise salary of male employees by 10% and Female employees by 15%.

Below is the query that I've used but can't achieve required result in Oracle11g.

merge into salary
using employees on 
salary.eid = employees.eid
when matched then
update set
    salary.salary = 1.1*salary where employee.gender = 'M' ,
    salary.salary = 1.15*salary where employee.gender = 'F';

I got below error message:

SQL Error: ORA-00969: missing ON keyword 00969. 00000 - "missing ON keyword" *Cause:
*Action:

Avrajit Roy

There are two things which you need to consider in the snippet provided.

  1. ON clause should always be accompanied by "()".
  2. WHERE clause in UPDATE statement is not correct. Hope this snippet helps.

    MERGE INTO SALARY USING EMPLOYEES 
    ON (salary.eid = employees.eid)
    WHEN MATCHED THEN
      UPDATE
      SET salary.salary = DECODE(employee.gender,'M',1.1*salary,'F',1.15*salary) ;
    

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

update one table with data from another using derived key value

Insert records into one table using key from another table

Update data in one table from data in another table

UPDATE values from one table using values from another table

Netezza - update one table with max data from another table

Retrieve data from one table and insert/update in another table in mysql

How to Replace and Update Data From One Table to Another Table in MySQL

Select / Update records in one table that are LIKE words selected from another table column with multiple records

Using PDO to look up records in one table and append data to another

SQL: Join records in one table with count from another using CASE

Can I make an update trigger using data from one table to update another?

Update one table by aggregating data of another table

How to update oracle table in Python using data from another table

update one table from another selected table

How to update one table from another table?

How to update the records from another table

Ecto - how to asynchronously update a batch of records from one table with respect to another table

How to insert multiple records from one table into another on update of third table in MySQL

Select from one table if no records found in another

Randomly Assign Records From One Table to Another

Get records from one table, based on related data from another table

How to copy data into empty table from another one by UPDATE?

Get a column data from one table and update it to another column from another table - MYSQL

Update a column for some rows in a table using another set of records from the same table

Update one column of Table A and copy the data from another table which is Table B

Append data from one table to another table

Copy Data from one table to another table

Update records on a table based on IDs from another table

Validate Record Data from Records in another table