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

  • Home
  • SEARCH
  • 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 8235023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:39:56+00:00 2026-06-07T18:39:56+00:00

I have a script to count a users points in a simple achievements type

  • 0

I have a script to count a users points in a simple achievements type script, then display them on a web page in order. I have the following mySQL function, but if a user doesn’t have any points as yet (i.e there is no ‘pa.userid’ to be found, then the user does not get fetched at all)

SELECT u.userid,
SUM(IF(pa.plus = '1', pa.points_amount, 0)) - SUM(IF(pa.plus = '0', pa.points_amount, 0)) AS points
FROM awarded_points pa,
users u WHERE u.userid = pa.userid 
GROUP BY u.userid 
ORDER BY points DESC 
LIMIT 10

How would i go about making the above code include users that haven’t yet got any points? Is it a complicated change?

  • 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-07T18:39:57+00:00Added an answer on June 7, 2026 at 6:39 pm

    Use a left outer join

    SELECT u.userid,
           SUM(IF(pa.plus = '1', pa.points_amount, 0)) - SUM(IF(pa.plus = '0', pa.points_amount, 0)) AS points
    FROM users u
    LEFT OUTER JOIN awarded_points pa ON u.userid = pa.userid 
    GROUP BY u.userid 
    ORDER BY points DESC 
    LIMIT 10
    

    See that great explanation of joins

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

Sidebar

Related Questions

I have the following call in my RoR script: Foo.where(event = 'Login').group('user_id').order('user_id ASC').count() This
I have this script that displays all the users images which i will display
Okay so I have this web site search script and I'm trying to count
I want to display part of the script any where on the web page
I have script like this : fullscript.sh if [ ! -f /opt/laks/linux-2.6.33.2.tar.bz2 ] then
I have script which allows to display Bing search results. I can call for
I have made the following script to upload a csv and import it into
The following script I have tried to run in MS server management studio and
First let me explain that I have this script that should let users enter
:-) I have this script, which find a users position taken from the number

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.