I’m trying to run a MYSQL query on my PHP page.
I think I need some sort of IF STATEMENT.
I’m just not sure how to even go about doing this.
I need data from 2 seperate tables.
From the first table (users) I need the field value “points”
and then from the second table (bank) I need the field value “bank_money”
I then need to add these together to get a total.
The problem I have is that if a user doesn’t have a bank account then
it needs to set the field value “bank_money” as ‘0’. Hope this makes sense.
This was an attempt. But it’s not working. It doesn’t add the users.points + ‘BankTotal’ together.
What am I doing wrong? Can anyone maybe help me or give me some advice. I would really appreciate it so much
SELECT users.username,
users.points,
bank.bank_money,
if(bank.bank_money != '',bank.bank_money,bank.bank_money = '0') AS 'BankTotal',
SUM(users.points + 'BankTotal') AS 'total'
FROM users
LEFT OUTER JOIN bank ON bank.username = users.username
GROUP BY username
ORDER BY 'total' DESC