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 940909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:02:01+00:00 2026-05-15T22:02:01+00:00

I have a table that stores transaction information. Each transaction is has a unique

  • 0

I have a table that stores transaction information. Each transaction is has a unique (auto incremented) id column, a column with the customer’s id number, a column called bill_paid which indicates if the transaction has been paid for by the customer with a yes or no, and a few other columns which hold other information not relevant to my question.

I want to select all customer ids from the transaction table for which the bill has not been paid, but if the customer has had multiple transactions where the bill has not been paid I DO NOT want to select them more than once. This way I can generate that customer one bill with all the transactions they owe for instead of a separate bill for each transaction. How would I build a query that did that for me?

  • 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-15T22:02:02+00:00Added an answer on May 15, 2026 at 10:02 pm

    Returns exactly one customer_id for each customer with bill_paid equal to ‘no’:

    SELECT 
        t.customer_id
    FROM 
        transactions t
    WHERE 
        t.bill_paid = 'no'
    GROUP BY
        t.customer_id
    

    Edit:
    GROUP BY summarises your resultset.
    Caveat: Every column selected must be either ‘grouped by’ or aggregated in some fashion. As shown by nikic you could use SUM to get the total amount owed, e.g.:

    SELECT 
        t.customer_id
        , SUM(t.amount) AS TOTAL_OWED
    FROM 
        transactions AS t
    WHERE 
        t.bill_paid = 'no'
    GROUP BY
        t.customer_id
    

    t is simply an alias.
    So instead of typing transactions everywhere you can now simply type t. The alias is not necessary here since you query only one table, but I find them invaluable for larger queries. You can optionally type AS to make it more clear that you’re using an alias.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that stores all the volunteers, and each volunteer will be
Say I have a table called xml that stores XML files in a single
I have a database table that stores imported information. For simplicity, its something like:
I have a table (venues) that stores all the possible venues a volunteer can
I have a basic property bag table that stores attributes about my primary table
I have a table that has redundant data and I'm trying to identify all
I have a table that stores messages from one user to another. messages(user_id,friend_id,message,created_date). My
I have a stored procedure that returns values from a temp table. In my
I have a stored procedure that ideally should be able to accept a list/table
I have a table that got into the db_owner schema, and I need it

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.