-1

I am trying to update a table, but my query is not correct. I don't know where I am making a mistake. Here it is:

UPDATE employee 
SET image = '123.jpg' 
WHERE employee.emp_id=personal_data.emp_Id;

Where emp_Id is a primary key in personal_data table and a foreign key in employee table .

Giorgi Nakeuri
  • 35,155
  • 8
  • 47
  • 75
  • Tag your DBMS. If it's MS-SQL you can join the tables like a normal `SELECT` and then change the `SELECT` to an `UPDATE` and specify the table's alias. `UPDATE a set ...` – Sean May 18 '16 at 09:17
  • this thread should help you ... [Update with Join](http://stackoverflow.com/questions/1293330/how-can-i-do-an-update-statement-with-join-in-sql) – RafaelK May 18 '16 at 09:20
  • Tag the dbms used!!! You've already got a couple of product specific answers and tips... – jarlh May 18 '16 at 09:34

2 Answers2

1

Try like this:

UPDATE E 
SET E.image = '123.jpg' 
FROM personal_data P 
INNER JOIN employee  E
    ON E.emp_id = P.emp_id
Giorgi Nakeuri
  • 35,155
  • 8
  • 47
  • 75
mohan111
  • 8,633
  • 4
  • 28
  • 55
0

You can use this query.

UPDATE employee  
SET E.image = '123.jpg' 
FROM employee,personal_data
where employee.emp_id = personal_data.emp_id
Sandeep Kumar
  • 1,172
  • 1
  • 9
  • 22