Title: SQL Error
Last modified: August 18, 2016

---

# SQL Error

 *  [checoivan](https://wordpress.org/support/users/checoivan/)
 * (@checoivan)
 * [20 years, 10 months ago](https://wordpress.org/support/topic/sql-error-2/)
 * I started to get this SQL error when trying to view comments on a post. So I 
   thought about posting how I solved it, since what I did was modifying a WP file.
 * The error was:
 * <b>WordPress database error: [You have an error in your SQL syntax; check the
   manual that corresponds to your MySQL server version for the right syntax to 
   use near ‘ORDER BY post_date ASC LIMIT 1’ at line 1]
    SELECT ID,post_title FROM
   wp_posts WHERE post_date > ” AND post_date < ‘2005-06-27 09:03:57’ AND post_status
   = ‘publish’ AND ID != ORDER BY post_date ASC LIMIT 1 </b>
 * **Solution:
    in the /wp-include/ directory I edited the template-functions-link.
   php file and in this line:
 * `
    return @$wpdb->get_row("SELECT ID,post_title FROM $wpdb->posts $join WHERE
   post_date > '$current_post_date' AND post_date < '$now' AND post_status = 'publish'
   $sqlcat $sql_exclude_cats AND ID != $post->ID ORDER BY post_date ASC LIMIT 1");
 * <strong>I added single quotes to $Post->ID
    </strong>
 *  return @$wpdb->get_row("SELECT ID,post_title FROM $wpdb->posts $join WHERE post_date
   > '$current_post_date' AND post_date < '$now' AND post_status = 'publish' $sqlcat
   $sql_exclude_cats AND ID != '$post->ID' ORDER BY post_date ASC LIMIT 1");
 * and now it's working, hope it helps someone else.

Viewing 1 replies (of 1 total)

 *  [lassmann](https://wordpress.org/support/users/lassmann/)
 * (@lassmann)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/sql-error-2/#post-227167)
 * brilliant – been looking for help for a while! and yours works – many thanks 
   indeed!

Viewing 1 replies (of 1 total)

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

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [lassmann](https://wordpress.org/support/users/lassmann/)
 * Last activity: [20 years, 1 month ago](https://wordpress.org/support/topic/sql-error-2/#post-227167)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
