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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:32:32+00:00 2026-05-26T16:32:32+00:00

The project I’m working on right now needs a reference system (currently they have

  • 0

The project I’m working on right now needs a reference system (currently they have 50K members). I decided to add ref and ref_id field in members table.

Structure of members table;

id (int auto),
admin (enum (1,0)),
ref (enum (1,0)),
ref_id (int),
country_id (int),
city_id(int),
town_id(int),
totalRef (int),
fullName (varchar),
registrationDate (datetime)

I would like to list referers data which has new members between 2 dates. I wanted to provide a bit more details so I also tried to add country, city, and town in the query. I tried following query but I don’t think this is a good approach to go with considering it takes really long time to load ;

SELECT m.id, m.fullName, m.country_id, m.city_id, m.town_id, m.totalRef,
(select name from country where country.id = m.country_id) as countryName,
(select name from city where city.id = m.city_id) as cityName,
(select name from town where town.id = m.town_id) as townName,
(select count(id) from members where members.ref_id = m.id AND ref_id > 0 AND registrationDate BETWEEN '2011.11.04 00:00:00' AND '2011.11.04 23:59:59') as newRef

FROM members as m 

WHERE

m.country_id = '224' AND 
m.city_id = '4567' AND
m.town_id = '78964' AND 
m.admin = '0' AND 
m.ref = '1' 

ORDER BY newRef DESC 
LIMIT 0, 25

I will be glad if you could help me about this problem. Thank you in advance.

  • 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-26T16:32:33+00:00Added an answer on May 26, 2026 at 4:32 pm

    Something like this –

    SELECT
      m.id,
      m.fullName,
      m.country_id,
      m.city_id,
      m.town_id,
      m.totalRef,
      cnt.name countryName,
      ct.name cityName,
      t.name townName,
      m2.newRef
    FROM members as m 
      LEFT JOIN country cnt
        ON cnt.id = m.country_id
      LEFT JOIN city ct
        ON ct.id = m.city_id
      LEFT JOIN town t
        ON t.id = m.town_id
      LEFT JOIN (
        SELECT ref_id, COUNT(id) newRef FROM members
          WHERE ref_id > 0 AND registrationDate BETWEEN '2011.11.04 00:00:00' AND '2011.11.04 23:59:59'
          GROUP BY ref_id
        ) m2
        ON m2.ref_id = m.id
    WHERE
      m.country_id = '224' AND 
      m.city_id = '4567' AND
      m.town_id = '78964' AND 
      m.admin = '0' AND 
      m.ref = '1' 
    ORDER BY
      newRef DESC 
    LIMIT
      0, 25;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Project I'm working on uses jQuery. I have a series of Ajax calls being
My project needs to have a number of administrators, out of which only one
Project: http://design.vitalbmx.com/fave/news.html When I click Add to favorites button (under main pic), in Chrome
Every project invariably needs some type of reporting functionality. From a foreach loop in
A project I'm working on at the moment involves refactoring a C# Com Object
My project is based on spring framework 2.5.4. And I try to add aspects
My project is currently using a svn repository which gains several hundred new revisions
The project is ASP.NET 2.0, I have never been able to reproduce this myself,
Project Euler I have recently begun to solve some of the Project Euler riddles.
Project Euler 126 says: If we then add a second layer to this solid

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.