title: MySQL syntax Error; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 4
body: <p>I get the following mySQL error listed below and was wondering how can I fix it.</p>
  
  <pre><code>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 4
  </code></pre>
  
  <p>Here is my MySQL code below.</p>
  
  <pre><code>$q = "SELECT COUNT(DISTINCT tags.tag) FROM tags INNER JOIN articles_tags ON articles_tags.tag_id = tags.id INNER JOIN users ON articles_tags.user_id = users.user_id WHERE users.active IS NULL AND users.deletion = 0";
  $r = mysqli_query ($mysqli, $q) or trigger_error("Query: $q\n&lt;br /&gt;MySQL Error: " . mysqli_error($mysqli));
  $row = mysqli_fetch_array ($r);
  $records = $row[0];
  </code></pre>
  
  <p>Here is my tables.</p>
  
  <pre><code>CREATE TABLE tags (
  id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  tag VARCHAR(255) NOT NULL,
  PRIMARY KEY (id)
  );
  
  
  CREATE TABLE articles_tags (
  id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  tag_id INT UNSIGNED NOT NULL,
  article_id INT UNSIGNED NOT NULL,
  user_id INT UNSIGNED NOT NULL,
  date_created DATETIME NOT NULL,
  unique_id CHAR(32) NOT NULL,
  PRIMARY KEY (id),
  UNIQUE KEY (tag_id, unique_id)
  );
  </code></pre>