Title: Multi-part queries?
Last modified: August 20, 2016

---

# Multi-part queries?

 *  [mikefulton](https://wordpress.org/support/users/mikefulton/)
 * (@mikefulton)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/multi-part-queries/)
 * Is it possible to do multiple queries in a single call to any of the $wpdb class
   methods?
 * Here’s what I want to do… I have a database table that contains records describing
   banner ads. Depending on the advertising program, there might be just one or 
   two ads in each size, or there might be a bunch. However, I want to give the 
   ads from the different programs equal weight.
 * That is, if there are 2 ads from Amazon, 96 from “ad-setup1” and 56 from “ad-
   setup2”, I don’t want to see the ads from “ad-setup1” 48 times more often than
   the ads from Amazon. In order to accomplish this, I first need to randomly select
   the ad program, then use that info to help me select an individual ad.
 * Here’s what I would *like* to do:
 *     ```
       SET @src=(SELECT DISTINCT source from ads order by rand() limit 0,1);
       SELECT * FROM ads WHERE source=@src ORDER BY id;
       ```
   
 * The problem is, it doesn’t work. Any attempt to issue multiple queries fails.
 * Does anybody have any data on this? My guess is that the reason is that the $
   wpdb class is calling the old mysql* functions, which don’t support this concept,
   instead of the newer mysqli* functions which do.
 * Any ideas?

Viewing 1 replies (of 1 total)

 *  Thread Starter [mikefulton](https://wordpress.org/support/users/mikefulton/)
 * (@mikefulton)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/multi-part-queries/#post-2090780)
 * By the way, yes, I know how to accomplish the result by making separate calls.
   I was just hoping for a more efficient solution.

Viewing 1 replies (of 1 total)

The topic ‘Multi-part queries?’ is closed to new replies.

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 1 reply
 * 1 participant
 * Last reply from: [mikefulton](https://wordpress.org/support/users/mikefulton/)
 * Last activity: [14 years, 12 months ago](https://wordpress.org/support/topic/multi-part-queries/#post-2090780)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
