hye!
Im a newbie in MySQL and Php, i got a problem to update column in db. Here is the issue:
i have 2 tables named 'apply' and 'balance'.
When user apply for leave, the system will deduct the value from table:balance based on apply.leaveType = balance.@column name. My problem is i dont know how to update the column value based on the apply.leaveType value from other table.
i try to do this but it doesnt make sense:
Hope someone can help me. Any helps are appreciated.
Im a newbie in MySQL and Php, i got a problem to update column in db. Here is the issue:
i have 2 tables named 'apply' and 'balance'.
Code:
Table: apply userId | leaveType |daysApply 1 | Annual | 3 2 | Medical | 1 Table: balance userId | Annual | Medical 1 | 14 | 3 2 | 14 | 3
When user apply for leave, the system will deduct the value from table:balance based on apply.leaveType = balance.@column name. My problem is i dont know how to update the column value based on the apply.leaveType value from other table.
i try to do this but it doesnt make sense:
Code:
UPDATE `balance`, `apply`
SET `balance.Annual`=`balance.Annual`-`apply.daysApply`,
`balance.Medical`=`balance.Medical`-`apply.daysApply`
WHERE `balance.Annual`=`apply.leaveType`
AND `balance.Medical`=`apply.leaveType`
AND `balance.userId`=`apply.userId`
Comment