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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:48:24+00:00 2026-06-08T05:48:24+00:00

I have several tables: table user: id firstname lastname 1 John Doe 2 Jane

  • 0

I have several tables:

table user:
id  firstname   lastname
1   John      Doe
2   Jane      Skith
3   will      Smith
...

table member:
member_id    member_user_id member_status member_activated_by
10         1              yes           partner 1
11         1              yes           partner 2
12         1              yes           partner 3
13         2              yes           partner 2
14         3              no            ----
...

table points:
points_id    points_user_id points_value points_date
10         1              10           2012-02-15 
11         2              15           2012-02-15 
12         2              20           2012-02-15 
13         1              5            2012-02-15 
14         3              30           2012-02-15 
15         1              12           2012-02-15 
...

So results SHOULD be:
 id1 - John Doe:   27 Points
 id2 - Jane Skith: 35 Points
 id3 - will Smith: nothing (not activated)

Problem is, that id1 brings 81 Points (as he has been actiavted 3 times …)

This is my current mysql string (shortened…)

SELECT points_user_id, SUM( points_value ) AS points_total, id, firstname, lastname
FROM user
JOIN member ON member.member_user_id = user.id
JOIN points ON points.points_user_id = user.id
WHERE 1
AND member_status = 'yes'
GROUP BY points_user_id
ORDER BY points_total DESC 
LIMIT 0 , 100

.. so far it “almost” works as desired.

BUT: A user may have sevaral partners that activated him “into the activation” table.

Now when this is called, I get a duplication of points_total (it will be counted as many times, as the uesr has been activated by partners … ) This does not make to much sense in a rankling list…

How can I get only “one” points_total for each user_id

Hope you understand, what I want to achieve … Thanks a lot!

  • 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-08T05:48:26+00:00Added an answer on June 8, 2026 at 5:48 am

    I think that this should work, instead of join with activation make a subselect where you will get only one row per user_id then join with this subselect, I’m not sure if this is the MySql sintax but it should show you the way. The only remark is that the fields that you choose inside the inner query may not change for a same user_id

    SELECT user_id, SUM( point_row ) AS points_total, user_data...,...
        FROM points
        JOIN user_data AS UD
        ON UD.user_id = points.user_id
    
    JOIN ( SELECT field1,field2,field3, MAX(activation.user_id) as user_id 
      FROM activation WHERE activation_info = 'yes'
      GROUP BY field1,field2,field3 AS ACTIV )  AS ACTIV
      ON user_data.user_id = AS ACTIV.user_id
    
    WHERE points.points_status = '1'
    AND   ACTIV.activation_info = 'yes'
    GROUP BY points.user_id
    ORDER BY total DESC 
    LIMIT 0 , 100
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My User entity class have several member variables (e.g. String firstName) which are persisted
I have article table and several user tables a_user , b_user , ... with
Okay, so I have several tables Vote Contest ContestSegment ContestRegistration Submittable User The relationship
I have a table with user items. Each user may have several types of
I have several tables: CREATE TABLE [dbo].[Tracks]( [Id] [uniqueidentifier] NOT NULL, [Artist_Id] [uniqueidentifier] NOT
I have several tables, books, bookcategories, categories bookcategories is a join table to allow
I have a main Table, with several child tables. TableA and TableAChild1 and TableAChild2.
I have a table which has several one to many relationships with other tables.
In an existing DB, we have several tables associated with a central USERS table.
I'm beginning work on a web application that will have several distinct user types,

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.