Title: Retrieving conditional SQL data from wpdb
Last modified: August 20, 2016

---

# Retrieving conditional SQL data from wpdb

 *  [tabletskopen](https://wordpress.org/support/users/tabletskopen/)
 * (@tabletskopen)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/retrieving-conditional-sql-data-from-wpdb/)
 * Hello everyone,
 * Thank you for reading this topic. I’m having difficulties retrieving information
   from the WordPress db. I know what information I want from my database but I 
   don’t exactly know how to code it. I hope you guys can help me started.
 * Here is what I want to achieve.
 * I want to add a couple of tables to the WPdb which contains information about
   product prices and links to images. Each table represents a supplier. This part
   I can do using a tool to import a CSV file.
 * The next part is to create a function in the function.php to extract the information
   from the tables. Each post gets a specific productnumber in a Custom Field. When
   the post is created the function should be called and looks at the productnumber
   and checks if the productnumber matches a field in de productnumber column in
   each table. When a field matches, the other fields in the row should be remembered.
   When all tables are checked then the result should be a list of prices sorted
   on the lowest price first together with the corresponding images
 * I know that I should call the global $wpdb to connect to the database. It’s especially
   the conditional SQL queries I’m having difficulties with.
 * Does this make any sence? I hope you guys could help me started with the coding
   on this. Many thanks in advance!

The topic ‘Retrieving conditional SQL data from wpdb’ is closed to new replies.

## Tags

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

 * 0 replies
 * 1 participant
 * Last reply from: [tabletskopen](https://wordpress.org/support/users/tabletskopen/)
 * Last activity: [13 years, 9 months ago](https://wordpress.org/support/topic/retrieving-conditional-sql-data-from-wpdb/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
