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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:22:42+00:00 2026-05-28T16:22:42+00:00

I have two table User userID username email 1 abc abc@abc.com 2 def def@def.com

  • 0

I have two table

User

userID username     email
  1       abc    abc@abc.com
  2       def    def@def.com
  3       ghi    ghi@ghi.com

Referral

 refID userID      invEmail
   1      1      abc@def.com
   2      1      omg@mog.com
   3      1      def@def.com

So what i plan is to give a invited user 5 point meanwhile a inviter 10 point, so basically userID 1 gained 30 meanwhile userID 2 gained 5. The point i can do in PHP but one part i faced difficulty is when a invEmail to be identified. I don’t mind separating into multiple queries if its will work.

How do i show this in sql?

I tried something like

SELECT *, count(r.userID) FROM user u, referral r WHERE u.userID = r.userID OR u.email = r.invEmail GROUP BY r.userID

It returned wrong value.

What i would like it to return, how much count is there inviter and invitee(matched email who has registered based on inviter invitation)

How should i do it?

Thank you.

Edit: i forgot to add something into question, what if i wanted the inviter to receive 10 points only if invitee registered? what i meant is that, only if invEmail exists in u.email then only userID received 10 point. Sorry for my mistake.

  • 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-28T16:22:43+00:00Added an answer on May 28, 2026 at 4:22 pm

    You might be able to do something like this:

    select points.userId, points.username, points.email, sum(points.points)
    FROM
    (select u.*, count(*)*10 as points
      from user u
        join referral on u.userID = r.userID
        join user verify_user on r.invEmail = verify_user.email
      group by u.userID, u.username, u.email
    UNION
    select u.*, count(*)*5 as points
      from user u
        join referral on u.email = r.invEmail and u.userID != r.userID
      group by u.userID, u.username, u.email
    ) as points
    group by points.userId, points.username, points.email
    

    I think you need two separate selects to get the points for each type of registration, combined with a union statement.

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

Sidebar

Related Questions

I have two tables like User and UserInfo UsersInfo UserId UserName Email Password LastLoginDate
I have two tables, in which one user can have several contacts: User(UserId, UserName)
I have two models, user and group. I also have a joining table groups_users.
I have two tables. The first is user ; this consists of username and
I have two tables User ID UserName 1 Name1 2 Name2 3 Name3 4
I have the two tables below. The table jobs will have a user id
Say, I have two tables like these: Table group Table user +----+-----------+ +----+----------+------+----------+ |
I have a User table defined like this: CREATE TABLE Users( UserId int IDENTITY(1,1)
I've got the following problem: I have two tables: (simplified) +--------+ +-----------+ | User
I have a simple database with two tables. Users and Configurations. A user has

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.