0
How do I perform a QUERY
in the database in 5 different tables and return the values I want, example:
I am performing a search system (my first) and need to capture the following values: Candidate Name, Resume Title and Vacancy Category. Now let’s get the information:
- The candidate’s name is in the table
wp_users
; - The title of the curriculum is in the table
wp_posts
; - The category of the vacancy is in the table
wp_terms
; wp_users
relates directly towp_posts
;wp_posts
relates directly towp_term_relationships
;wp_term_relationships
relates directly towp_term_taxonomy
;wp_term_taxonomy
relates directly towp_terms
;- But there is one condition... A query must be made in the table
wp_usermeta
wheremeta_value = '_jm_candidate_field_clocknow_user_btn'
andmeta_key = 'value_1'
; - The table
wp_usermeta
is directly related towp_users
wp_usermeta
-> wp_users
-> wp_posts
-> wp_term_relationships
-> wp_term_taxonomy
-> wp_terms
The query I’m doing is not returning values:
$resultados = $wpdb->get_results( "SELECT $wpdb->users.display_name, $wpdb->posts.post_title, $wpdb->terms.name, $wpdb->usermeta.meta_key, $wpdb->usermeta.meta_value
FROM $wpdb->usermeta
WHERE $wpdb->usermeta.meta_key = '_jm_candidate_field_clocknow_user_btn' AND $wpdb->usermeta.meta_value = 'value_2'
INNER JOIN $wpdb->users ON $wpdb->usermeta.user_id = $wpdb->users.ID
INNER JOIN $wpdb->posts ON $wpdb->posts.post_author = $wpdb->users.ID
INNER JOIN $wpdb->term_relationships ON $wpdb->term_relationships.object_id = $wpdb->posts.ID
INNER JOIN $wpdb->term_taxonomy ON $wpdb->term_taxonomy.term_id = $wpdb->term_relationships.term_taxonomy_id
INNER JOIN $wpdb->terms ON $wpdb->terms.term_id = $wpdb->term_taxonomy.term_taxonomy_id;" );
Would it be logical that this wrong?
Just do an Inner Join.
– Jéf Bueno
Only using INNER JOIN in a query is possible?
– Rodrigo Fontes
Possibly yes, I would need more details (and better know the structure of the bank) to say for sure.
– Jéf Bueno