MySQL Forums
Forum List  »  Newbie

Combining several queries from Wordpress Database
Posted by: Matthew Steele
Date: December 26, 2014 12:52PM

I need help combining several queries I have created into one query. Below are the individual queries. At the moment I am running them individually and then combining them in Excel.

This is the main query:

SELECT wp_wp_pro_quiz_statistic.statistic_ref_id, sum(wp_wp_pro_quiz_statistic.points) AS TotalPoints, wp_wp_pro_quiz_statistic_ref.quiz_id, wp_wp_pro_quiz_statistic_ref.user_id, wp_wp_pro_quiz_master.name, wp_users.user_email
FROM ((`wp_wp_pro_quiz_statistic` LEFT JOIN `wp_wp_pro_quiz_statistic_ref` ON wp_wp_pro_quiz_statistic.statistic_ref_id = wp_wp_pro_quiz_statistic_ref.statistic_ref_id) LEFT JOIN `wp_wp_pro_quiz_master` ON wp_wp_pro_quiz_statistic_ref.quiz_id = wp_wp_pro_quiz_master.id) LEFT JOIN
wp_users ON wp_wp_pro_quiz_statistic_ref.user_id = wp_users.ID
GROUP BY statistic_ref_id, wp_wp_pro_quiz_statistic_ref.quiz_id, wp_wp_pro_quiz_statistic_ref.user_id, wp_wp_pro_quiz_master.name, wp_users.user_email
ORDER BY wp_wp_pro_quiz_statistic.statistic_ref_id DESC;

The following queries need to be matched up using user_id:

This one gets the users first name:

SELECT wp_usermeta.*
FROM wp_usermeta
WHERE (((wp_usermeta.meta_key)="first_name"))
ORDER BY wp_usermeta.umeta_id DESC;

and this one gets their last name:

SELECT wp_usermeta.*
FROM wp_usermeta
WHERE (((wp_usermeta.meta_key)="last_name"))
ORDER BY wp_usermeta.umeta_id DESC;

and this one gets an invite code used by the user - there is a field called meta_key which value is secure_invite_invitation_code for this invitation code, but here you will see I am filtering out just a specific invite code ("calibre"):

SELECT wp_usermeta.*
FROM wp_usermeta
WHERE (((wp_usermeta.meta_value)="calibre"))
ORDER BY wp_usermeta.umeta_id DESC;

I want these last three queries to be incorporated into the main query - the first one shown above.

I'd appreciate any help anyone can offer.

Many thanks.

Options: ReplyQuote


Subject
Written By
Posted
Combining several queries from Wordpress Database
December 26, 2014 12:52PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.