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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:53:02+00:00 2026-06-13T09:53:02+00:00

I got a table for sales order and purchase order. Sales order Date Amount

  • 0

I got a table for sales order and purchase order.

Sales order

Date   Amount

 26/10  120
 26/10  130 
 26/10  50
 27/10  50 
 27/10  60

Purchase Order

Date   Amount

 26/10  200 
 26/10  300 
 26/10  100
 27/10  100 
 27/10  100

I want to display the total sales and total purchase by date.

E.g.

 Date   Total Sales Total Purchases 
  26/10    300            600 
  27/10    110            200

My SQL query is like this but it doesnt work.

$query = "Select o.date, o.Amount AS Sales, p.date, p.Amount AS Purchases
          From customerorder o
          right join Purchaseorder p on o.date = p.date
          order by o.date";

Please help! 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-06-13T09:53:03+00:00Added an answer on June 13, 2026 at 9:53 am
        SELECT COALESCE(o.date, p.date) date, Sales, Purchases
          FROM (SELECT date, SUM(amount) Sales FROM CustomerOrder GROUP BY date) o
     FULL JOIN (SELECT date, SUM(amount) Purchases FROM PurchaseOrder GROUP BY date) p
            ON o.date = p.date
      ORDER BY date
    

    MySQL doesn’t support FULL JOIN, so specifically for MySQL, you can use

        SELECT o.date, Sales, Purchases
          FROM (SELECT date, SUM(amount) Sales FROM CustomerOrder GROUP BY date) o
     LEFT JOIN (SELECT date, SUM(amount) Purchases FROM PurchaseOrder GROUP BY date) p
            ON o.date = p.date
     UNION ALL
        SELECT date, NULL, SUM(amount) Purchases
          FROM PurchaseOrder p2
         WHERE NOT EXISTS (SELECT *
                           FROM CustomerOrder o2
                           WHERE o2.date = p2.date)
      GROUP BY date
      ORDER BY date
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got a Sales table which has fields like upgrade[yes/no] date upgraded[datetime] user[username]
I got a table that saves executed purchase orders. For a report I want
got a table with dates and prices. Date Price 2012-01-01 25 2012-01-05 12 2012-01-10
I got a table in my HTML and I want to generate new temporary
I've got a TABLE that's actually being used for its intended purpose, to display
id car make sales 1 panamera porsche 100 2 italia ferrari 200 3 volante
We are developing an inventory tracking system. Basically we've got an order table in
Ive got table with columns: PlayerId Points I would like to get 100 best
I've got a simple Model like this: class Order(models.Model): created = model.DateTimeField(auto_now_add=True) total =
I have got a table [newsletter] in the db, which saves the email address,

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.