简体   繁体   中英

update data from another table postgresql using IN

I have 2 tables :table1 and table2.When using this query,

SELECT * 
FROM table1 a 
WHERE a.name IN (SELECT name FROM table2 )

The result is 20.

When I want update data based on this query

UPDATE table1 SET number='1' 
FROM table1 a 
WHERE a.name IN (SELECT name FROM table2)

The result is all the number will be set to 1 instead of only 20.The default number is 0.

Try this

UPDATE table1 t1 SET number=1
JOIN table2 t2 ON t1.name = t2.name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM