php - Update query for two different Column in two different table-MySQL -
i working on upwork type project , want create update query bids. user has free bids (which gets default per month) , pro bids can buy amount.
if apply on job want update -1
job_quota (if not 0 already), -1
pro bids in ascending order.
my table structure (in user table):
users
job_quota -------->id 12---------------->53
buy_bids
id---->no_bids--->amount_paid--->user_id 1-----> 20------------>20---------------> 53 2-----> 20------------>20---------------> 53 3-----> 20------------>20---------------> 53
i have idea - not how implement mysql query:
$query=<<< sql update users set job_quota=job_quota-1 if ( job_quota !=0 ) else update buy_bids set no_bids =no_bids-1 user_id=53 sql;
can suggest me how can achieve it, not looking accurate solution need , suggestion should try achieve this.
many thanks.
something this?
update users ,buy_bids set users.job_quota = case when users.job_quota !=0 users.job_quota-1 else users.job_quota end, buy_bids.no_bids =case when users.job_quota =0 buy_bids.no_bids-1 else buy_bids.no_bids end users.user_id=buy_bids.user_id , users.user_id=53;
this not tested. suggestion. i'm not sure else condition,so added users.job_quota =0
. change accordingly.
Comments
Post a Comment