![](/img/trans.png)
[英]There are two columns in the new table(table1 join table2) which have the same column name, how to get the values of both respectively
[英]Compare columns on two tables, and update table1 if it's column matches a column in table2
好的,所以我有兩個桌子。 兩者都充滿了電子郵件。 我需要將列更新為“ true”或“ false”,具體取決於電子郵件地址是否出現在另一個表中。 目前,我的計划是用PHP編寫一個函數來檢查每一行,但是它非常慢(在一個循環中檢查一個具有25萬行的表與一個具有13萬行的表的循環,這意味着32 500000000個查詢)。
在sql中,有沒有更簡單或更快速的方法? 我一直在搜索,但沒有發現太多。
要更新table1
並將列在另一個表中未找到則設置為TRUE,如果存在則為FALSE,則可以使用LEFT JOIN
update table1
left join table2 on table1.email = table2.email
set table1.bool_col = case when table2.email is null
then 'true'
else 'false'
end
這將立即更新所有記錄。 然后,您可以對另一個表執行相同的操作。 只需切換表名。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.