Shafiq Ahmed
Shafiq Ahmed

Reputation: 57

Merge and replace table id with name

table employee:

+----+------------+
| id | firstname  |
+----+------------+
| 1  |   name1    | 
+----+------------+

table orders:

+----+--------+
| id |  eid   |
+----+--------+
|  1 |   2    |        
+----+--------+

Is possible with one query get this result?

+----+--------+
| id |  eid   |
+----+--------+
| 1  | name1  |        
+----+--------+

Upvotes: 0

Views: 52

Answers (2)

John Woo
John Woo

Reputation: 263733

You can't directly do update if the datatype of orders.eid is int. Change it to sting first then execute this UPDATE statement,

UPDATE  orders a
        INNER JOIN employee b
            ON a.id = b.id
SET     a.eid = b.firstName

Upvotes: 1

Brian Willis
Brian Willis

Reputation: 23864

I think this is what you're asking for, but it's not entirely clear from your question.

select orders.id, employee.firstname
from orders
inner join employee on orders.eid = employee.id

Upvotes: 0

Related Questions