Title: SQL JOIN syntax? help!
Last modified: August 18, 2016

---

# SQL JOIN syntax? help!

 *  Resolved [jwilliams](https://wordpress.org/support/users/jwilliams/)
 * (@jwilliams)
 * [20 years, 2 months ago](https://wordpress.org/support/topic/sql-join-syntax-help/)
 * This question pertains to my WordPress database. I need to JOIN 3 SQL tables 
   to extract information from the wp_comments table.
 * dbname: wordpress
 * table: wp_comments
    field: ID field: post_name
 * table: wp_post2cat
    field: post_id field: category_id
 * table: wp_categories
    field: category_nicename field: cat_ID
 * The idea is that wp_comments.ID = wp_post2cat.post_id, and wp_post2cat.category_ID
   = wp_categories.cat_ID
 * I need a properly syntaxed SQL query written as a string for a php variable, 
   $query. I’ve written the gernal idea out below, where things inside [](http://codex.wordpress.org/)
   need to be put into proper SQL
 * $query=”SELECT [[wp_comments.ID, wp_comments.post_name]] FROM [all three tables](http://codex.wordpress.org/all_three_tables)
   WHERE [[wp_categories.category_nicename=SomeCategoryName]] ORDER [[by wp_comments.
   ID, descending]] LIMIT [[to $delimiter, a php variable]]”
 * If you are an SQL buff and have a spare moment, I’d REALLY apreciate a moment
   of your time to help me out here! Thanks so much – Jameson

Viewing 1 replies (of 1 total)

 *  Thread Starter [jwilliams](https://wordpress.org/support/users/jwilliams/)
 * (@jwilliams)
 * [20 years, 2 months ago](https://wordpress.org/support/topic/sql-join-syntax-help/#post-375387)
 * Oh. I can just require_once(‘./blog/wp-config.php’); and then use all those query_posts()
   options before including the loop on any damn page i feel like outside of ./blog!
 * WordPress just got like, five hundred times cooler for me. What a joke to think
   I had to know that complicated database query! Ha.
 * Sorry, I’m excited.

Viewing 1 replies (of 1 total)

The topic ‘SQL JOIN syntax? help!’ is closed to new replies.

## Tags

 * [advanced](https://wordpress.org/support/topic-tag/advanced/)
 * [categories](https://wordpress.org/support/topic-tag/categories/)
 * [Merge](https://wordpress.org/support/topic-tag/merge/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [sql](https://wordpress.org/support/topic-tag/sql/)
 * [tables](https://wordpress.org/support/topic-tag/tables/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [jwilliams](https://wordpress.org/support/users/jwilliams/)
 * Last activity: [20 years, 2 months ago](https://wordpress.org/support/topic/sql-join-syntax-help/#post-375387)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
