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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:39:58+00:00 2026-05-29T07:39:58+00:00

I have a like the one below that does a minus from another select.

  • 0

I have a like the one below that does a minus from another select. The problem I have is that if the second SELECT (the one to do minus with) returns NULL, the full query returns NULL even if the first query has values. Seems like MySQL thinks 1-NULL=NULL. How can I fix this?

SELECT round(sum(iv.`amount`)) - 
(
 SELECT round(sum(pay.`amount`)) amountSum

     FROM invoice iv
    LEFT JOIN invoiceFactoring ivf on ivf.invoiceID=iv.invoiceID 
    LEFT JOIN user systemuser ON (systemuser.userID=iv.ownerUserID)
    LEFT JOIN Payment pay ON (pay.`invoiceID`=iv.`invoiceID`)
     WHERE 
        (iv.invoiceStateID = 2 OR iv.invoiceStateID = 3) 
     AND 
    (ivf.`invoiceFactoringProcessID` = 7)
     AND     (pay.`paymentMethodID` = 1 OR pay.`paymentMethodID` = 2)
     AND systemuser.`groupID` = 1 
     AND iv.`disabled` <> 1 
     AND ivf.`invoiceExpiryDate` BETWEEN date_add(now(), INTERVAL - 28 DAY) AND date_add(now(), INTERVAL - 21 DAY)

)
    FROM invoice iv
    LEFT JOIN invoiceFactoring ivf on ivf.invoiceID=iv.invoiceID 
        LEFT JOIN user systemuser ON (systemuser.userID=iv.ownerUserID)
    WHERE 
    (iv.invoiceStateID = 2 OR iv.invoiceStateID = 3)
        AND 
    (ivf.`invoiceFactoringProcessID` = 7 or ivf.`invoiceFactoringProcessID`)
    AND systemuser.`groupID` = 1 
    AND iv.`disabled` <> 1   /* ta bort de som är inaktiva*/    
    AND ivf.`invoiceExpiryDate` BETWEEN date_add(now(), INTERVAL - 28 DAY) AND date_add(now(), INTERVAL - 21 DAY)
  • 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-29T07:39:59+00:00Added an answer on May 29, 2026 at 7:39 am

    perhaps you can wrap the “inner” sql with an IFNULL

    SELECT round(sum(iv.`amount`)) - 
    IFNULL((
     SELECT round(sum(pay.`amount`)) amountSum
     FROM invoice iv
     LEFT JOIN invoiceFactoring ivf on ivf.invoiceID=iv.invoiceID 
     LEFT JOIN user systemuser ON (systemuser.userID=iv.ownerUserID)
     LEFT JOIN Payment pay ON (pay.`invoiceID`=iv.`invoiceID`)
     WHERE 
        (iv.invoiceStateID = 2 OR iv.invoiceStateID = 3) 
     AND 
        (ivf.`invoiceFactoringProcessID` = 7)
     AND     (pay.`paymentMethodID` = 1 OR pay.`paymentMethodID` = 2)
     AND systemuser.`groupID` = 1 
     AND iv.`disabled` <> 1 
     AND ivf.`invoiceExpiryDate` BETWEEN date_add(now(), INTERVAL - 28 DAY) 
     AND date_add(now(), INTERVAL - 21 DAY)
    ),0)
    
    FROM invoice iv
    LEFT JOIN invoiceFactoring ivf on ivf.invoiceID=iv.invoiceID 
        LEFT JOIN user systemuser ON (systemuser.userID=iv.ownerUserID)
    WHERE 
    (iv.invoiceStateID = 2 OR iv.invoiceStateID = 3)
        AND 
    (ivf.`invoiceFactoringProcessID` = 7 or ivf.`invoiceFactoringProcessID`)
    AND systemuser.`groupID` = 1 
    AND iv.`disabled` <> 1   /* ta bort de som är inaktiva*/    
    AND ivf.`invoiceExpiryDate` BETWEEN date_add(now(), INTERVAL - 28 DAY) AND date_add(now(), INTERVAL - 21 DAY)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a query like the one below: SELECT t1.id, t1.Name FROM Table1
So I have a TreeView like the one below, with certain items being hidden.
I have seen many programs consisting of structures like the one below typedef struct
I have a comma separated list of strings like the one below. a,b ,c
I have an XML file which has many section like the one below: <Operations>
I have an Excel spreadsheed like the one shown below A B 10.02.2007 10
I have to define the grammar of a file like the one shown below.
So I have a java hashmap like below: hMap.put(1, One); hMap.put(2, Two); hMap.put(3, Two);
I have a app that uses a classic email like layout like the one
I have one like this: CALayer *layer = stripeButton.layer; CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:@bounds.origin.y];

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.