I have a table with user payment details, and another table with a list of users. I want to get the balance of all users from the payment details, but only for users that are not banned (which is a column in the users table).
I am somewhat new to nested queries so I am not sure how to do this?
Here is what I have tried so far…
mysql_query("
SELECT SUM(balance)
FROM payment_details
WHERE (SELECT ban
FROM users
WHERE username=username
) != '1'
")
Note: Username is a column in both tables.
The above query does not work.
To Recap: There are two tables: payment_details and users. I want to add together the balance column for all the users that are not banned.
Don’t use a subquery here. Instead, use a
JOIN.