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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:36:50+00:00 2026-06-02T16:36:50+00:00

As an example, there is a table that has Sales Reps and their sales

  • 0

As an example, there is a table that has Sales Reps and their sales listed in a table. Two of the rep ID’s are for the same Rep, so I need to be able to combine these two rows into one in a query while still displaying the rest of the rows. Whether this is done in the SQL query, or in PHP either way would work.

So here is what the table would look like:

ID    Sales
100   $5
101   $10
102   $2
500   $3

I need it to output like this:

ID    Sales
100   $8
101   $10
102   $2

Where ID 100’s sales is a sum of both 100 and 500.

I’m sure this can’t be too hard, but I’m not that familiar with SQL or PHP yet, trying to learn though. Thank you.

  • 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-06-02T16:36:52+00:00Added an answer on June 2, 2026 at 4:36 pm

    use two separate query then union

    SELECT ID, SUM(Sales) FROM table WHERE ID IN (100,500)
    UNION ALL
    SELECT ID, Sales FROM table WHERE ID NOT IN (100,500)
    
    • 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 has two columns, ID and Value. For this example
I've got a table that has, for example, ID and Name . There are
I have two rows from a table that has many columns. How do I
I want to create a database that has the table for sales and services
Here is a simple example: Assume I have a customer table that has a
For example, I have a table, and there is a column named 'Tags'. I
How do you select a random rows from a table? For example, if there
I need to explain this by example: Is there a best practice or preference
I have a table that has a bunch of fields. The fields can be
I have a table that has a view_count column. I would like to increment

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.