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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:29:01+00:00 2026-06-08T12:29:01+00:00

The Count works fine with one related table, but when I add the Sum

  • 0

The Count works fine with one related table, but when I add the Sum I get overinflated results in the Count.

SELECT Orders.kp_OrderID AS `Order #`, 
    Orders.t_ServiceLevel AS `Service Level`, 
    Customers.t_CustCompany AS Company, 
    Orders.t_JobName AS `Job Name`, 
    Orders.t_JobStatus AS `Status`, 
    Orders.d_JobDue AS Due, 
    Orders.ti_JobDue AS Time, 
    COUNT(OrderItems.kf_OrderID) AS `Line Item`, 
    SUM(
        `OrderItemComponents`.`n_QuantityPrintMaterial` * (
        `OrderItemComponents`.`n_WidthInInches` * `OrderItemComponents`.`n_HeightInInches` / 144
            )
        ) AS SqFt, 
    Orders.nb_JobFinished AS Finished
FROM Orders 
     INNER JOIN OrderItems ON Orders.kp_OrderID = OrderItems.kf_OrderID
     INNER JOIN Customers ON Orders.kf_CustomerID = Customers.kp_CustomerID
     INNER JOIN OrderItemComponents ON OrderItemComponents.kf_OrderID = Orders.kp_OrderID
    WHERE Orders.d_JobDue > (
        DATE_SUB(CURDATE(), INTERVAL 60 DAY)
         )
    GROUP BY Orders.kp_OrderID
    ORDER BY `Line Item` DESC
  • 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-08T12:29:02+00:00Added an answer on June 8, 2026 at 12:29 pm

    Switch your COUNT line to:

    COUNT(DISTINCT OrderItems.kf_OrderID) AS `Line Item`
    

    When adding the line

    INNER JOIN OrderItemComponents 
      ON OrderItemComponents.kf_OrderID = Orders.kp_OrderID
    

    you returned many more rows since an OrderItem can, I assume, contain multiple components.

    UPDATE

    Try using this in place if your COUNT statement:

    (SELECT COUNT(OrderItems.kf_OrderID) 
     FROM OrderItems.kf_OrderID 
     WHERE OrderItems.kf_OrderID=Order.kf_OrderID) AS `Line Item`,
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am having a problem adding COUNT to my query. the query works fine
Can someone explain me why this works: select val1, val2, count(case when table2.someID in
How come the following code works fine... <ul class=searchList> @if (Model.Count() > 0) {
My SQL expression which works fine displays results for months and it will be
I've written this code to find duplicates and it works fine: SELECT * FROM
I have the following query to one of my database tables: select count(*) as
I have engineered a process monitor which works fine but after 5 or 6
Hi I tried bin/katta search IndexName Query the above one is works fine and
I would like to select one of the child node of my treeview get
I have a table being generated from an array of NSManagedObjects. This works fine

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.