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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:24:22+00:00 2026-05-26T20:24:22+00:00

I am trying to make some sort of SQL Query where I only get

  • 0

I am trying to make some sort of SQL Query where I only get the 10 people with the most referrals, but with minimum 1 referral.

My Table looks like this:

CREATE TABLE IF NOT EXISTS `beta_list` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `email` varchar(250) NOT NULL,
  `referrer` int(10) NOT NULL,
  `referral_code` int(10) NOT NULL,
  UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;

I have tried something like this:

SELECT 
     email,
     referral_code as refcode,
     (SELECT COUNT(*) FROM beta_list WHERE referrer=refcode) as referrals
  FROM 
     beta_list 
  WHERE
     referrals > 0
  ORDER BY
     referrals DESC
  LIMIT
     10

But it just says “Unknown column ‘referrals’ in ‘where clause'”.

I am no sql guru, I am only just beginning to learn more complex sql queries, so any help on how to achieve something like this would be deeply appreciated!

Cheers!

  • 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-26T20:24:23+00:00Added an answer on May 26, 2026 at 8:24 pm

    Try this – Add an outer query to extract the results from inner query –

    select ref.email, ref.refcode, ref.referrals from 
    (
      SELECT 
         email,
         referral_code as refcode,
         (SELECT COUNT(*) FROM beta_list WHERE referrer=refcode) as referrals
      FROM 
         beta_list
    ) as ref
    WHERE
         ref.referrals > 0
    ORDER BY
         ref.referrals DESC
    LIMIT
         10
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make some text bold using HTML, but I'm struggling to get
I am trying to make some sort of timeline, but I can not keep
I'm trying to make some simple XML with Java and org.w3c.dom, but I got
I'm trying to make some social share buttons at my site, but the urls
I'm trying to make it working for quite some time,but just can't seem to
Currently I'm trying to make some sort of vertical auto-scrolling. This is my code
I'm trying to make a design for some sort of IExecutable interface. I will
I'm trying to make visual states available in the ViewModel as some sort of
I've been trying to make some methods that will sort a linked list by
I learning python and django and trying to make some sort of simple forum.

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.