Title: sql queries
Last modified: August 20, 2016

---

# sql queries

 *  Resolved [itsjohn](https://wordpress.org/support/users/itsjohn/)
 * (@itsjohn)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/sql-queries-1/)
 * i’ve been doing customized sql queries and I’m stumped one thing. I can’t seem
   to query both publish and future at the same time, it queries the future and 
   repetitively posts that to however much I set the limit at.
 * currently this is what i have,
 *     ```
       $querying = $wpdb->get_results("
                             SELECT *
                             FROM $wpdb->posts, $wpdb->terms, $wpdb->term_relationships, $wpdb->term_taxonomy
                             WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id
                               AND $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id
                               AND $wpdb->term_taxonomy.term_id = $wpdb->terms.term_id
                               AND $wpdb->posts.post_status = 'publish'
                               OR $wpdb->posts.post_status = 'future'
                               AND $wpdb->terms.term_id IN (1,2,3,4)
                               ORDER BY $wpdb->posts.post_date DESC
                               LIMIT 5
                           ");
       ```
   

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [wondersly](https://wordpress.org/support/users/wondersly/)
 * (@wondersly)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/sql-queries-1/#post-2427034)
 * looks like you’re missing some parens:
 *  …AND ( $wpdb->posts.post_status = ‘publish’
    OR $wpdb->posts.post_status = ‘
   future’ )…
 * Anytime you’re mixing ANDs and ORs, you’ll generally need ’em.
 *  Thread Starter [itsjohn](https://wordpress.org/support/users/itsjohn/)
 * (@itsjohn)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/sql-queries-1/#post-2427050)
 * awesome, thanks man!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘sql queries’ is closed to new replies.

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 2 replies
 * 2 participants
 * Last reply from: [itsjohn](https://wordpress.org/support/users/itsjohn/)
 * Last activity: [14 years, 4 months ago](https://wordpress.org/support/topic/sql-queries-1/#post-2427050)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
