Title: Nested Query with get-&gt;results
Last modified: August 30, 2016

---

# Nested Query with get->results

 *  Resolved [andywt](https://wordpress.org/support/users/andywt/)
 * (@andywt)
 * [11 years ago](https://wordpress.org/support/topic/nested-query-with-get-results/)
 * I am struggling trying to get a nested query to work. I am using a plugin, CFDB,
   that stores its data in a way that can be retrieved using a pivot query. What
   I am trying to do is wrap a query on the results of the pivot query and subsequently
   update the data. I’ve tried a variety of methods but had no success other than
   getting the pivot query to deliver an array.
 * Here is my code:
 *     ```
       $queryresults = $wpdb->get_results("Select * FROM
       							(SELECT <code>submit_time</code> AS 'Submitted',
       								max(if(<code>field_name</code>='Route', <code>field_value</code>, null )) AS 'Route',
        								max(if(<code>field_name</code>='Contact Information', <code>field_value</code>, null )) AS 'Contact Information',
        								max(if(<code>field_name</code>='UniqueID', <code>field_value</code>, null )) AS 'UniqueID',
        							GROUP_CONCAT(if(<code>file</code> is null or length(<code>file</code>) = 0, null, <code>field_name</code>)) AS 'fields_with_file'
        							FROM <code>fg_cf7dbplugin_submits</code>
       							WHERE <code>form_name</code> = '2015 Flag Database Missing Flag'
       							GROUP BY <code>submit_time</code>
       							ORDER BY <code>uniqueID</code> ASC
       							LIMIT 0,5000)");
       		foreach ( $queryresults as $queryresults ) {
       			echo "<pre>"; print_r( $queryresults ); echo "<pre>";
       	}
       ```
   
 * Nothing is ever returned. If I do a query with the inner SELECT only, the array
   is returned, so I’m thinking my nesting is causing the issue.
 * Thanks for your help.

Viewing 1 replies (of 1 total)

 *  Thread Starter [andywt](https://wordpress.org/support/users/andywt/)
 * (@andywt)
 * [11 years ago](https://wordpress.org/support/topic/nested-query-with-get-results/#post-6187184)
 * Solved this by accessing the $wpdb directly.

Viewing 1 replies (of 1 total)

The topic ‘Nested Query with get->results’ is closed to new replies.

 * 1 reply
 * 1 participant
 * Last reply from: [andywt](https://wordpress.org/support/users/andywt/)
 * Last activity: [11 years ago](https://wordpress.org/support/topic/nested-query-with-get-results/#post-6187184)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
