monkey coder
monkey coder

Reputation: 163

joining two tables and update a column value

I want to change the value of the year level of users id 1 from tbl_profile to '3rd', and i want to reference the name 'captain america' from the table because they have the same user_id.

here is my example table:

tbl_profile
users_id    year_level
1           none

tbl_usersinfo
users_id        full_name
1           captain america

here is my query:

UPDATE tbl_profile AS p
SET p.year_level = '3rd'
LEFT JOIN
tbl_usersinfo AS i
ON
i.users_id = p.users_id
WHERE
i.full_name = 'captain america';

I want it to be like this, but i know that this query is not possible because i haven't specified where the full_name column came from:

UPDATE tbl_profile AS p
SET p.year_level = '3rd'
WHERE i.full_name = 'captain america'
LEFT JOIN
tbl_usersinfo AS i
ON
i.users_id = p.users_id

Upvotes: 0

Views: 70

Answers (1)

Akhil
Akhil

Reputation: 479

Use this query:

UPDATE tbl_profile
SET year_level='3rd'
WHERE users_id IN (
  SELECT users_id
  FROM tbl_usersinfo WHERE full_name = 'captain america');

Upvotes: 2

Related Questions