Help with a query
Posted: Mon Jul 09, 2007 8:58 am
Here is my deal. I have 3 tables called rbf_user, rb_raketracking_usermap, rb_raketracking
I am trying to write a query that will get all of the users from rbf_user who's referral id != NULL and who has at least 1 status = 1 in rb_raketracking_usermap and who has at least 1 row in rb_raketracking where net_rake != NULL and data_date = $data_date. But I only want to return the userid and the referralid from rbf_user.
Right now the only way I can think of to do this is through 3 queries but this is taking my script over a minute to finish. Here is sudo code of what I have now:
The big problem is, is that there are over 5000 users who have people they referred and not all of those users who where referred by them are in the rb_raketracking_usermap or in the rb_raketracking. I just want the users who where referred by someone and who have a valid row in the rb_raketracking and a valid row in the rb_raketracking_usermap.
Can anyone help me write this query?
I am trying to write a query that will get all of the users from rbf_user who's referral id != NULL and who has at least 1 status = 1 in rb_raketracking_usermap and who has at least 1 row in rb_raketracking where net_rake != NULL and data_date = $data_date. But I only want to return the userid and the referralid from rbf_user.
Right now the only way I can think of to do this is through 3 queries but this is taking my script over a minute to finish. Here is sudo code of what I have now:
Code: Select all
SELECT userid, referralid FROM rbf_user where referralid != ""
while $info = that query
SELECT * FROM rb_raketracking_usermap WHERE fk_vb_user_id = $info->referralid AND status = "1"
if rows returned
while $usermap = that query
SELECT * FROM rb_raketracking WHERE room_username = $usermap->room_username AND data_date = $data_date AND is_final = "1"
while $raketracking = that query
calculate $rakeback
else
skip this user
if $rakeback == 0
skip this user
end loopCan anyone help me write this query?