Title: SQL request problem
Last modified: February 24, 2017

---

# SQL request problem

 *  [Roman Sarvarov](https://wordpress.org/support/users/rom4i/)
 * (@rom4i)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/sql-request-problem/)
 * Hey guys. Hope you will understand my English.
    So, I have 2 taxonomies: city
   and street.
 * I need to get postmeta for one of my plugins.
 * Working code for only one taxonomy:
 *     ```
       SELECT * 
       FROM $wpdb->postmeta 
       LEFT JOIN $wpdb->posts 
       ON($wpdb->posts.ID = $wpdb->postmeta.post_id) 
       LEFT JOIN $wpdb->term_relationships 
       ON ($wpdb->postmeta.post_id = $wpdb->term_relationships.object_id) 
       LEFT JOIN $wpdb->term_taxonomy 
       ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) 
       WHERE 
       meta_key LIKE 'rwp_rating%' 
       AND ($wpdb->term_taxonomy.taxonomy = 'city' AND $wpdb->term_taxonomy.term_id = '2') 
       ```
   
 * but if I append `AND ($wpdb->term_taxonomy.taxonomy = 'street' AND $wpdb->term_taxonomy.
   term_id = '5')`
    it returns empty result
 * Also I tried to do that:
 *     ```
       SELECT * FROM $wpdb->postmeta 
       LEFT JOIN $wpdb->posts ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) 
       LEFT JOIN $wpdb->term_relationships ON ($wpdb->postmeta.post_id = $wpdb->term_relationships.object_id) 
       LEFT JOIN $wpdb->term_taxonomy as t1 ON ($wpdb->term_relationships.term_taxonomy_id = t1.term_taxonomy_id) 
       LEFT JOIN $wpdb->term_taxonomy as t2 ON ($wpdb->term_relationships.term_taxonomy_id = t2.term_taxonomy_id) 
       WHERE meta_key LIKE 'rwp_rating%' AND (t1.taxonomy = 'city' AND t1.term_id = '2') AND (t2.taxonomy = 'street' AND t2.term_id = '3331');
       ```
   
 * And it doesn’t working too.
 * p.s. I need to match both, like: city = 2 AND street = 2
    not: city = 2 OR street
   = 2
    -  This topic was modified 9 years, 3 months ago by [Roman Sarvarov](https://wordpress.org/support/users/rom4i/).
    -  This topic was modified 9 years, 3 months ago by [Roman Sarvarov](https://wordpress.org/support/users/rom4i/).

The topic ‘SQL request problem’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [Roman Sarvarov](https://wordpress.org/support/users/rom4i/)
 * Last activity: [9 years, 3 months ago](https://wordpress.org/support/topic/sql-request-problem/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
