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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:14:07+00:00 2026-05-23T06:14:07+00:00

The following sql call works fine, returns the correct total retail for customers: SELECT

  • 0

The following sql call works fine, returns the correct total retail for customers:

SELECT  customer.id,
        customer.first_name, 
        customer.last_name,
        SUM(sales_line_item_detail.retail) AS total_retail
FROM sales_line_item_detail
    INNER JOIN sales_header 
        ON sales_header.id = sales_line_item_detail.sales_header_id
    INNER JOIN customer 
        ON customer.id = sales_header.customer_id
GROUP BY sales_header.customer_Id
ORDER BY total_Retail DESC
LIMIT 10

However, i need it to return the customers telephone and email addresses as well.. please keep in mind that not all customers have an email address and telephone number. whenever i left join the email and numbers tables, it throws the total_retail amount off by thousands and I am not sure why.

The following query gives completely wrong results for the total_retail field:

    SELECT  customer.id,
        customer.first_name, 
        customer.last_name,
        IF(
            ISNULL( gemstore.customer_phone_numbers.Number), 
            'No Number..', 
            gemstore.customer_phone_numbers.Number
            ) AS Number,
        IF(
            ISNULL(gemstore.customer_emails.Email), 
            'No Email...', 
            gemstore.customer_emails.Email
            ) AS Email,
        SUM(sales_line_item_detail.retail) AS total_retail,
FROM sales_line_item_detail
    INNER JOIN sales_header 
        ON sales_header.id = sales_line_item_detail.sales_header_id
    INNER JOIN customer 
        ON customer.id = sales_header.customer_id
    LEFT JOIN gemstore.customer_emails 
        ON gemstore.customer_emails.Customer_ID = gemstore.customer.ID
    LEFT JOIN gemstore.customer_phone_numbers 
        ON gemstore.customer_phone_numbers.Customer_ID = gemstore.customer.ID
GROUP BY sales_header.customer_Id
ORDER BY total_Retail DESC
LIMIT 10

Any help figuring out why it is throwing off my results is greatly appreciated.

Thanks!

  • 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-23T06:14:08+00:00Added an answer on May 23, 2026 at 6:14 am

    Is it possible that there are multiple records for a Customer_ID in either the customer_emails or customer_phone_numbers tables?

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

Sidebar

Related Questions

I have the following shortened classic ASP code that makes a SQL insert call...
The following SQL Lite statement in Trac SELECT id, changetime / 1000000 as 'MODIFIED',
I have the following SQL Server query: SELECT area FROM places WHERE REPLACE(area,'-',' ')
I have the following SQL snippet within a select statement: CASE WHEN wot.id LIKE
I have the following SQL query: SELECT r.BEZEICHNUNG AS BEZEICHNUNG, r.ID AS ID, ra.BEZEICHNUNG
I have following SQL statementL: select DATE(bla), count(*) from tableA group by DATE(bla) UNION
Hi I have the following script which works fine running on IIS but when
The following sql will return a count of how many users have played a
In the following SQL statement, SQLite sorts correctly but MySQL does not: However, if
I currently have the following SQL query that lists all the names of all

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.