mysql - How to update a sql table only if other condition exist in another table -


i have 2 sql separated tables in database:

ds_users, containing: group_id 

and

ds_users_data_members, containing: data_gender 

i set / update group_id 6 data_gender equal 2.

all morning tried solve issue , without success.

please help. thank much

i assuming there must relation between 2 tables. without relationship cannot update record in 1 table checking condition in table.

let's ds_users table has column user_id exist in ds_users_data_members table.

so, can write following query update records in ds_users data_gender=2 in ds_users_data_members table

sql server example

update    t set       group_id=6      ds_users t inner join ds_users_data_members t1 on t.user_id=t1.user_id     t1.data_gender=2 

mysql example

update    ds_users t inner join ds_users_data_members t1 on t.`user_id`=t1.`user_id` set       t.`group_id`=6     t1.`data_gender`=2; 

you can replace column name of user_id have given in table.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -