PrakashT
PrakashT

Reputation: 901

How to remove negative values from result query in mysql?

My question is how to remove negative values from query results.My sql query returns both positive and negative values. i want only top 10 positive numbers.But i don't know how to remove negative numbers from result set

Here is my query:

SELECT (select account_name from mk_account_master where account_id = atm.account) as account,sum(debit)-sum(credit) as balance,(select Branch_name from mk_branch_master where Branch_id = atm.books) as branch_name from mk_account_transaction_master as atm where account in (SELECT account_id from mk_account_master where type = 'contractor') GROUP BY account,books limit 10 

Query result :

account                     balance      branch_name    
CTA-test@vendor-8761239088  -1320.00    Anthiyur Colony-Erode-Tamil Nadu-1
CTA-test@vendor-8761239088  -1200.00    raj_New@project_Anthiyur_3
CTA-test@vendor-8761239088  -1200.00    raj_Erode_Anthiyur_4
CTA-test@vendor-8761239088  +1500.00    raj_Erode_Anthiyur_5

Upvotes: 0

Views: 2427

Answers (2)

chintan sureliya
chintan sureliya

Reputation: 53

Your query seems preety complex. You can make it easy to read and optimized by using JOINS

Upvotes: 0

Kenth Joshua Espina
Kenth Joshua Espina

Reputation: 87

Try this:

SELECT Balance(field) FROM table WHERE Balance >= 0

Upvotes: 1

Related Questions