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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:00:56+00:00 2026-06-01T03:00:56+00:00

My head is about to explode with everything I’ve read about SQL Server and

  • 0

My head is about to explode with everything I’ve read about SQL Server and Joins in the last 2 hours.

tbl_customers
-------------
IPaddress
CustomerID


tbl_purchases
-------------
OrderID (pkey)
CustomerID
OrderTotal

I want to get the total purchase amounts per IP address. There are more columns in the tbl_customers table, such that there are duplicate (IPaddress, CustomerID) rows. I have used the following query:

SELECT DISTINCT IPaddress, SUM(OrderTotal) FROM tbl_customers a
INNER JOIN tbl_purchases b ON a.CustomerID = b.CustomerID
GROUP BY IPaddress;

But it retrieves the duplicate rows from tbl_customers and causes the sum function to count the same purchase multiple times. What am I doing wrong? Efficiency isn’t really an issue as I’m dealing with under 10K records.

  • 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-01T03:00:57+00:00Added an answer on June 1, 2026 at 3:00 am
    SELECT tc.IPaddress,SUM(tp.OrderTotal)
    FROM (SELECT DISTINCT IPaddress,CustomerID FROM tbl_customers) tc,
         tbl_purchases tp
    WHERE tc.CustomerID = tp.CustomerID
    GROUP BY tc.IPaddress;
    

    OR

    SELECT tc.IPaddress,SUM(tp.OrderTotal)
            FROM (SELECT DISTINCT IPaddress,CustomerID FROM tbl_customers) tc
                  INNER JOIN 
                 tbl_purchases tp
                 ON   tc.CustomerID = tp.CustomerID
     GROUP BY tc.IPaddress;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been scratching my head about this for the last 4 hours, trying out
My head is about to explode with this logic, can anyone help? Class A
I've been banging my head on this one specific issue for about 2 hours
Even though I have read a lot about it I can't get my head
My head is about to explode after looking into why this is not working
I've been banging my head over this issue for about 5 hours now, I'm
Okay, after pounding my head against the wall for about 2 hours, I need
My head is about to explode as I try to figure out the reason
My head hurts: I've read so many blogs about C++11x's move semantics that my
I've been banging my head against the desk for about 2 hours on this

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.