# \[help\] If statement query?

**URL:** <https://forum.kirupa.com/t/help-if-statement-query/269712>\
**Category:** programming\
**Created:** [August 31, 2008, 9:27am UTC](https://forum.kirupa.com/t/help-if-statement-query/269712 "2008-08-31T09:27:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![csj16](https://avatars.discourse-cdn.com/v4/letter/c/b5ac83/32.png) [@csj16](https://forum.kirupa.com/u/csj16)\
**Post date:** [August 31, 2008, 9:27am UTC](https://forum.kirupa.com/t/help-if-statement-query/269712/1 "2008-08-31T09:27:43Z")

</div>

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 😃

```auto
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 

```
