Title: SQL Query &#8211; Select only one category
Last modified: August 19, 2016

---

# SQL Query – Select only one category

 *  [rogerr](https://wordpress.org/support/users/rogerr/)
 * (@rogerr)
 * [17 years, 5 months ago](https://wordpress.org/support/topic/sql-query-select-only-one-category/)
 * Hi
 * I have a query that is working fine as follows
 *     ```
       <?php
       					global $wpdb;
       					$latest_posts = $wpdb->get_results('SELECT p.* FROM ' . $wpdb->posts . ' p LEFT JOIN ' . YAPB_TABLE_NAME . ' yi ON p.ID = yi.post_id WHERE p.post_type = \'post\' AND yi.URI IS NOT NULL ORDER BY RAND() LIMIT 0,' . $imagecount);
       					$thumbConfig = array('h=633','w=950','q=80'); //Change variables here
       				?>
       ```
   
 * I would like to modify it to only select from Category ID 536.
 * Help would be greatly appreciated
 * Rog
    [http://www.popcornphotography.com.au](http://www.popcornphotography.com.au)

The topic ‘SQL Query – Select only one category’ is closed to new replies.

## Tags

 * [sql](https://wordpress.org/support/topic-tag/sql/)

 * 0 replies
 * 1 participant
 * Last reply from: [rogerr](https://wordpress.org/support/users/rogerr/)
 * Last activity: [17 years, 5 months ago](https://wordpress.org/support/topic/sql-query-select-only-one-category/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
