Title: SQL database error
Last modified: August 18, 2016

---

# SQL database error

 *  Resolved [jakelowen](https://wordpress.org/support/users/jakelowen/)
 * (@jakelowen)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/sql-database-error/)
 * Help!
 * I have the following showing up at the bottom of my site.
 * 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”
   at line 1]
    SELECT COUNT(DISTINCT ID) FROM
 * The site is [http://www.jakelowen.com](http://www.jakelowen.com)
 * Any idea how to get rid of that?

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Thread Starter [jakelowen](https://wordpress.org/support/users/jakelowen/)
 * (@jakelowen)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/sql-database-error/#post-381816)
 * Still unresolved.. Anyone have an idea where to start tinkering to fix this problem?
 *  Thread Starter [jakelowen](https://wordpress.org/support/users/jakelowen/)
 * (@jakelowen)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/sql-database-error/#post-381818)
 * As i investigate more I see that the error occurs on all pages (main page, monthly
   archives, and other added wordpress pages) but does not occur on a particular
   posts permalink –
 * Does that help narrow it down for anybody?
 *  [Chris_K](https://wordpress.org/support/users/handysolo/)
 * (@handysolo)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/sql-database-error/#post-381819)
 * Still stumps me, but does cause a question to bubble up: What plugins are you
   running? And have you experimented with disabling some of ’em?
 *  Thread Starter [jakelowen](https://wordpress.org/support/users/jakelowen/)
 * (@jakelowen)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/sql-database-error/#post-381822)
 * Thanks handy –
 * I tried disabling all of them – to no avail.
 * i was running podpress, skippy.net’s backup and cron plugins.
 *  [Chris_K](https://wordpress.org/support/users/handysolo/)
 * (@handysolo)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/sql-database-error/#post-381823)
 * Well, now I reckon we’ll want to look at your theme’s footer.php. Would you be
   willing to put the contents of it in a pastebin somewhere and put a link to it
   here?
 *  Thread Starter [jakelowen](https://wordpress.org/support/users/jakelowen/)
 * (@jakelowen)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/sql-database-error/#post-381828)
 * Got it! I found the solution below:
 * The problem and the way akamanu.com PHP Certified Web Developer fixed:
 * Inside the file wp-includes/template-functions-links.php there is the following
   instruction around line 500:
 * $numposts = $wpdb->get_var(”SELECT COUNT(DISTINCT ID) FROM $fromwhere”); However
   the variable $fromwhere is not always initialized when the instruction is executed.
 * So we have changed the instruction to:
 * if(isset($fromwhere)){ $numposts = $wpdb->get_var(”SELECT COUNT(DISTINCT ID) 
   FROM $fromwhere”);}else{
    $numposts = 0;}
 * Now, I only have one more question – How do i get next/previous links on my archive
   pages?
 *  Thread Starter [jakelowen](https://wordpress.org/support/users/jakelowen/)
 * (@jakelowen)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/sql-database-error/#post-381830)
 * I am closing this post and making a new one that is more specific to my new problem.
 * Thanks everyone!

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘SQL database error’ is closed to new replies.

## Tags

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

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

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
