Results 1 to 8 of 8
Apr 2, 2008, 12:48 #1
- Join Date
- Jan 2004
- 0 Post(s)
- 0 Thread(s)
Selecting filtered results from a table with 1 million rows
Hello MySQL Gurus!
I am trying to write an interesting query here and I am not sure if it all can be done in one step in the same query. Here is my dilemma:
I have a DB with two tables: mm_recipients and postal_codes. The first one has a list of users in my system and the second one a list of 1 million postal codes in Canada.
My objective is to select a list of 50 users that live less than 10Km away from a central location and are between 25 and 50 years old.
The MM_RECIPIENTS table has the following fields:
The table POSTAL_CODES has the following fields:
Now, there is a calculation to come up with the distance, but even ignoring this fact for now, how would I get all the information from the two tables?
This is what I currently have (which by the way pretty much crashes the server...):
SELECT * FROM mm_recipients, mm_recipients_lists, postal_codes WHERE mm_recipients.recipient_id=mm_recipients_lists.recipient_id AND mm_recipients_lists.list_id=7 AND (recipient_bday_year < 1983 AND recipient_bday_year > 1958) AND mm_recipients.postal_code = postal_codes.postal_code ORDER BY rand() LIMIT 0,50
Thanks a lot.