Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6615655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:29:22+00:00 2026-05-25T20:29:22+00:00

i have data 2 table like this Table Transaction ID | Amount 1 |

  • 0

i have data 2 table like this

Table Transaction

ID | Amount
1  | 200
2  | 300

Table Payment

ID | Transaction | Amount
1  | 1           | 200
2  | 2           | 150
3  | 2           | 100

then i using query

SELECT `transaction`.id AS `id`,
    `transaction`.amount AS amount,
    SUM(payment.amount) AS payment,
    `transaction`.amount - SUM(payment.amount) AS balance
FROM `transaction`
LEFT JOIN payment
    ON payment.`transaction` = `transaction`.id
GROUP BY payment.`transaction`;

and then i get data like this

id | amount | payment | balance
1  | 200    | 200     | 0
2  | 300    | 250     | 50

Now how do i make conditional to only show data which balance is more than 0?
Which is should only show row id 2

i tried do this query, but it give me error.

SELECT `transaction`.id AS `id`,
    `transaction`.amount AS amount,
    SUM(payment.amount) AS payment,
    `transaction`.amount - SUM(payment.amount) AS balance
FROM `transaction`
LEFT JOIN payment
    ON payment.`transaction` = `transaction`.id
WHERE `transaction`.amount - SUM(payment.amount) > 0
GROUP BY payment.`transaction`;

Thank you,
Gusde

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:29:23+00:00Added an answer on May 25, 2026 at 8:29 pm

    The “HAVING” SQL clause does what you are looking for. It like “WHERE”, except it runs after the JOINS and GROUP BY’s, and allows you filter based on the almost final output. It’s also useful for finding missing relationships between tables you’ve joined together.

    SELECT `transaction`.id AS `id`,
       `transaction`.amount AS amount,
        SUM(payment.amount) AS payment,
        `transaction`.amount - SUM(payment.amount) AS balance
    FROM `transaction`
    LEFT JOIN payment
        ON payment.`transaction` = `transaction`.id
    GROUP BY payment.`transaction`
    HAVING balance > 0;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a bit confused on this. I have a data table structured like this:
I have a table like this: Application,Program,UsedObject It can have data like this: A,P1,ZZ
I have a table like this... CustomerID DBColumnName Data 1 FirstName Joe 1 MiddleName
i have data like this. Table customer | customerId | fullName | sex |
I have a query like this: SELECT TABLE_NAME, COLUMN_NAME, IS_NULLABLE, DATA_TYPE FROM MY_DB.INFORMATION_SCHEMA.COLUMNS WHERE
I have three tables: page, attachment, page-attachment I have data like this: page ID
I have several sources of tables with personal data, like this: SOURCE 1 ID,
I have a table with a lot of repeated data that I'd like to
I have an Excel table with some data that I would like to export
I have a table with a few rows of data. I would like to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.