Hi everyone… I am OK at php and simple mysql. But I am absolute rubbish at genius level MySQL. Help! Is there anybody out there that is really good at mysql?? I don’t know how to write IF clauses, build short term tables or anything..
I can build happy eater sql statements separately, but haven’t a clue how to efficiently merge them into one effiecient whopper. Yikes, this needs real geniusql.
This is for a travelling-companion-website. When someone’s profile is activated by an admin person, I need an sql statement to search through the all members for similar people, prepare list of their member_id ready to email them: -
1. Find people who have matchfinder enabled
Select id, age, country from dt_members where matchfinder=’1’
This gets all the members, their age and resident country, who have match finder enabled
For each of the above people…
2. find people that are looking to travel to the same destination
destinations are stored in table destinations_x
each destinations_x record, has fields: id, profile_id and destinations_id
(each person can input as many destinations as they like)
Select profile_id from destination_x where destinations_id =’$destination’
(loop for each of the destinations in new persons profile)
This gets the ids of members with a similar destination in mind
2b. Resolve the profile_id to member_id
That’s right the profile_id, from the above, is different from member_id
Select member_id from profile where_id=’$profile_id’
3. find people that are looking for the same holiday type
holilday types are stored (as relationship) in table relationship_x
each relationship_x record, has fields: id, profile_id and relationship_id
(each person can input as many holiday types as they like)
Select profile_id from relationship_x where relationship_id =’$relationship’
(loop for each of the holiday types in new persons profile)
This gets the ids of members with a similar holiday type in mind
3b. Resolve the profile_id to member_id
Select member_id from profile where_id=’$profile_id’
Put in one nice list ready to go
Delete duplicates