title: SQLSTATE[42000]: Syntax error or access violation: 1064
body: <p>Should this query work, and if not how could I put a query inside another using PDOs in PHP ?</p>
  
  <p>Here is my query : </p>
  
  <pre><code>$userid = array($users-&gt;school_name_from_id($_SESSION['user_id']), $_SESSION['user_id'], $_SESSION['user_id']);
  $statementString =
    'SELECT * FROM schoolinfo 
     WHERE schoolinfo.school = ? AND 
       SELECT count(*) FROM friendstable 
         WHERE friendstable.user_ID = ? 
          AND frienstable.friend_ID = schoolinfo.id  &lt;= 0
     AND 
       SELECT count(*) FROM friendstable 
       WHERE friendstable.user_ID = schoolinfo.id 
         AND friendstable.friend_ID = ?  &lt;= 0 
     ORDER BY RAND()
     LIMIT 6';
  
  
          $stmt = $database-&gt;_link-&gt;prepare($statementString);
          $stmt-&gt;execute($userid);
          $array = $stmt-&gt;fetchAll(PDO::FETCH_ASSOC);
          print_r($array);
  </code></pre>
  
  <p>and here is the full error I get when it is run :</p>
  
  <pre><code>Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 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 'SELECT count(*) FROM friendstable WHERE friendstable.user_ID = '1' AND frienstab' at line 1' in C:\xampp\htdocs\thinkaztech\PHP\getSocialInformation.php:20 Stack trace: #0 C:\xampp\htdocs\thinkaztech\PHP\getSocialInformation.php(20): PDOStatement-&gt;execute(Array) #1 {main} thrown in C:\xampp\htdocs\thinkaztech\PHP\getSocialInformation.php on line 20
  </code></pre>