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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:52:18+00:00 2026-05-27T17:52:18+00:00

I’m sure this is an easy one, but I’ve been looking at it for

  • 0

I’m sure this is an easy one, but I’ve been looking at it for an hour and just can’t see it.

I have two tables on a sales/payment system, one that contains the different payment methods and associated details, and another that contains the sales including ID’s, totals and payment method.

At the end of the period, I want to bring up the total for all the different methods, or NULL or 0 if there was none.

This is the query I have:

SELECT m.method_id, m.description, SUM(s.total) as total 
FROM payment_method m 
         LEFT JOIN sale s ON s.payment_method = m.method_id 
 WHERE m.for_stock_keeping = 0 AND 
 (s.shift_id = ? OR s.shift_id IS NULL) 
 GROUP BY m.method_id;

It works fine until we start another shift with a new ID, then any payment methods that have been used in a previous shift no longer show up if no sales occur for that method.
i.e.: If I make 10 cash sales this shift, and then start a new shift Cash will no longer show up with a NULL value, but will only appear after a Cash sale has occurred and there is a value for it. This is not the behaviour I want.

Any help would be really appreciated!

Thanks,
Ryan.

  • 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-27T17:52:19+00:00Added an answer on May 27, 2026 at 5:52 pm

    The condition on s.shift_id in the WHERE clause is applied after the outer join; you need it applied before.

    You have two options (at least):

    SELECT m.method_id, m.description, SUM(s.total) as total 
      FROM payment_method m 
      LEFT JOIN sale s ON s.payment_method = m.method_id AND 
                           (s.shift_id = ? OR s.shift_id IS NULL)
     WHERE m.for_stock_keeping = 0 
     GROUP BY m.method_id, m.description;
    

    and:

    SELECT m.method_id, m.description, SUM(s.total) as total 
      FROM payment_method m 
      LEFT JOIN (SELECT * FROM Sale AS a WHERE a.shift_id = ? OR a.shift_id IS NULL) AS s
        ON s.payment_method = m.method_id 
     WHERE m.for_stock_keeping = 0 
     GROUP BY m.method_id, m.description;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I have some data like this: 1 2 3 4 5 9 2 6

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.