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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:08:04+00:00 2026-06-04T08:08:04+00:00

I have this following problem: I have two tables 1 table for customer bought

  • 0

I have this following problem:

I have two tables 1 table for customer bought items and the other for employee sales:

Table 1 (Emp)
EmpId 
ProductId
dateSold
Price
Qty

Table 2 (Cust)
CustomerId
ProductId
dateSold
Price
Qty

do this is the query im tring at the moment:

SELECT  SUM(EmployeeSales.productPrice * EmployeeSales.Qty + 
            userBoughtItems.ProductPrice * userBoughtItems.qty) AS Total, 
        EmployeeSales.dateSold, 
        userBoughtItems.dateSold AS Expr1
FROM    EmployeeSales 
INNER JOIN userBoughtItems ON EmployeeSales.dateSold = userBoughtItems.dateSold
GROUP BY EmployeeSales.dateSold, userBoughtItems.dateSold

I want to get the total of both tables on the same date…

  • 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-04T08:08:05+00:00Added an answer on June 4, 2026 at 8:08 am

    A join repeats the right table for every matching row in the left table. In your example I’d expect that to result in a lot of duplicated rows. Consider using a union instead:

    select  cast(dt as date)
    ,       sum(sales)
    from    (
            select  dateSold as dt
            ,       productPrice * Qty as sales
            from    EmployeeSales
            union all
            select  dateSold
            ,       ProductPrice * qty
            from    userBoughtItems
            ) as SubQueryAlias
    group by
            cast(dt as date)
    

    The subquery contains a list of all sales, and the outer query sums them per day.

    If you’re using SQL Sever 2005 or older, replace cast(dt as date) with dateadd(dd, 0, datediff(dd, 0, dt)).

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

Sidebar

Related Questions

This problem is giving me a real headache. I have two tables in my
I have the following problem: I want to compare two tables and see if
I have two tables (1) MonthlyTarget {SalesManCode, TargetMonthYear, TargetValue}; this table has 1966177 rows.
I have two tables one Employee and mailing Subscriptions Employee looks like this: Name
I have two tables: CREATE TABLE items ( root_id integer NOT NULL, id serial
I have two tables like the following hotels ------ hotelID hotelName Second table operators
I have a database with the following table structures... The Customer table has two
Never thought I'd have this problem :) The following snippet of code works in
I have the following problem. I am making this website you can see in
I have been working on the following problem from this book . A certain

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.