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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:14:22+00:00 2026-06-06T09:14:22+00:00

I found a lot of helpful information on stackoverflow, but a tiny bit is

  • 0

I found a lot of helpful information on stackoverflow, but a tiny bit is still missing to solve the following issue:

I have two tables userscores and userpoints like that:

#table userscores (saves userpoints each month) 

date          userid   points
2012-05-01    1        23
2012-06-01    1        34

#table userpoints (recent points) 

userid   points
1        23
2        10
3        15

I was able to find out how to calculate the differences between recent userpoints and stored userpoints (from table “userscores”) of the current month using:

SELECT userpoints.userid, userpoints.points - userscores.points AS mpoints 
    FROM `userpoints`,`userscores` 
    WHERE userpoints.userid=userscores.userid 
        AND YEAR(userscores.date) = YEAR(CURDATE()) 
        AND MONTH(userscores.date) = MONTH(CURDATE())
        AND userpoints.userid != ".$adminID."
    ORDER BY mpoints DESC;"

However, this query is only comparing the userid from both tables and ignoring the userids that exist in table userpoints and but do not exist in table userscores.

The query should be modified so that newly created userids (in table userpoints) are considered as scores as well.

I found out how to query to get the userids that do not exist in table userscores:

 SELECT userpoints.userid FROM `userpoints` 
      WHERE userpoints.userid 
           NOT IN(SELECT qa_userscores.userid FROM `qa_userscores`)

Now I have to combine both but trying the following does not work:

SELECT userpoints.userid, userpoints.points - userscores.points AS mpoints 
FROM `userpoints`,`userscores` 
WHERE ( 
    userpoints.userid = userscores.userid
    AND YEAR(userscores.date) = YEAR(CURDATE()) 
    AND MONTH(userscores.date) = MONTH(CURDATE())
    AND userpoints.userid != ".$adminID."
)
OR ( 
    userpoints.userid IN(SELECT userpoints.userid FROM `userpoints` 
        WHERE userpoints.userid 
            NOT IN(SELECT DISTINCT userscores.userid FROM `userscores`)) 
)
ORDER BY mpoints DESC;

Any help appreciated.

  • 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-06T09:14:24+00:00Added an answer on June 6, 2026 at 9:14 am
    SELECT userpoints.userid, userpoints.points - coalesce(userscores.points,0) 
                                                     AS mpoints 
        FROM `userpoints`
        left join `userscores` on userpoints.userid=userscores.userid         
            AND YEAR(userscores.date) = YEAR(CURDATE()) 
            AND MONTH(userscores.date) = MONTH(CURDATE())
        where userpoints.userid != ".$adminID."
        ORDER BY mpoints DESC;"
    

    The Left join automatically retains the rows on the left side even when there is no corresponding row on the right. All conditions you check on the right side must be in the Join Condition. Finally, you need to use a default value for the Right Side value when ther is none.

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

Sidebar

Related Questions

I have found a lot of information on using UIImagePickerController to let the user
I've found a lot of information on object oriented programming, but none of it
I have searched a lot on this topic. I found one answer on stackoverflow,
I have looked at a lot of answers but have not found a satisfactory
I have searched this up rather a lot, but come up with no helpful
i found a lot of questions about resizing images in .NET and whatnot, but
I have found a lot of topics about stress-testing web application. My goals are
I found a lot of Regex email validation in SO but I did not
I have looked for some info on this and haven't found anything very helpful.
I had a search and found lot's of similar regex examples, but not quite

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.