[英]joining two tables and update a column value
我想將用戶id 1的年級別的值從tbl_profile更改為“ 3rd”,並且我想從表中引用名稱“ captain America”,因為他們具有相同的user_id。
這是我的示例表:
tbl_profile
users_id year_level
1 none
tbl_usersinfo
users_id full_name
1 captain america
這是我的查詢:
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';
我希望它像這樣,但是我知道不可能執行此查詢,因為我沒有指定full_name列的來源:
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
使用此查詢:
UPDATE tbl_profile
SET year_level='3rd'
WHERE users_id IN (
SELECT users_id
FROM tbl_usersinfo WHERE full_name = 'captain america');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.