Title: SQL Syntax Error
Last modified: August 18, 2016

---

# SQL Syntax Error

 *  Resolved [bcreighton](https://wordpress.org/support/users/bcreighton/)
 * (@bcreighton)
 * [19 years, 5 months ago](https://wordpress.org/support/topic/sql-syntax-error-2/)
 * I’m working on archives by date and category ([http://wordpress.org/support/topic/69776?replies=13](http://wordpress.org/support/topic/69776?replies=13))
   and I have an SQL Syntax error. My mySQL knowledge is fairly limited, can anyone
   spot the error? Thanks!
 * `$arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`,
   MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts, $wpdb->post2cat
   WHERE id = post_id AND post_date < '$now' AND category_id = $mcat AND post_date!
   = '0000-00-00 00:00:00' AND post_status = 'publish' GROUP BY YEAR(post_date),
   MONTH(post_date) ORDER BY post_date DESC" . $limit);`

Viewing 1 replies (of 1 total)

 *  Thread Starter [bcreighton](https://wordpress.org/support/users/bcreighton/)
 * (@bcreighton)
 * [19 years, 5 months ago](https://wordpress.org/support/topic/sql-syntax-error-2/#post-495248)
 * got it – wasn’t carrying the catid over… 😀

Viewing 1 replies (of 1 total)

The topic ‘SQL Syntax Error’ is closed to new replies.

## Tags

 * [monthly](https://wordpress.org/support/topic-tag/monthly/)
 * [MySQL](https://wordpress.org/support/topic-tag/mysql/)

 * In: [Everything else WordPress](https://wordpress.org/support/forum/miscellaneous/)
 * 1 reply
 * 1 participant
 * Last reply from: [bcreighton](https://wordpress.org/support/users/bcreighton/)
 * Last activity: [19 years, 5 months ago](https://wordpress.org/support/topic/sql-syntax-error-2/#post-495248)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
