ok, realize may incredibly simple, brain frozen right now. need bit of assistance query. let's break down. have 2 tables (per example) , want update single table "undeliverable" status
customers table (tbl_customers):
+------------+-------------+ | customerid | custacctnum | +------------+-------------+ | 1 | 100100121 | | 2 | 100100122 | | 3 | 100100123 | | 4 | 100100124 | | 5 | 100100125 | +------------+-------------+ address table (tbl_address):
+-----------+------------+---------------+ | addressid | customerid | undeliverable | +-----------+------------+---------------+ | 1 | 1 | 0 | | 2 | 2 | 0 | | 3 | 3 | 0 | | 4 | 4 | 0 | | 5 | 5 | 0 | +-----------+------------+---------------+ dataset "undeliverable" customer account numbers (custacctnum)
100100121, 100100123, 100100124 and query update address table this
+-----------+------------+---------------+ | addressid | customerid | undeliverable | +-----------+------------+---------------+ | 1 | 1 | 1 | | 2 | 2 | 0 | | 3 | 3 | 1 | | 4 | 4 | 1 | | 5 | 5 | 0 | +-----------+------------+---------------+ this query have tried use
update tbl_address set undeliverable = 1 ( select custacctnum tbl_customers c inner join tbl_address on a.customerid = c.customerid ) in ( 100100121, 100100123, 100100124); any suggestions? thanks!
use mysql's multiple-table update syntax:
update tbl_address t join custacctnum c on c.customerid = t.customerid set t.undeliverable = 1 c.custacctnum in (100100121, 100100123, 100100124)
Comments
Post a Comment