title: Perform delete while inner joining table
body: <p>I want to delete an entry in my <strong>PAGES</strong> table. Upon deletion of it, it will cascade to <strong>OBJECTS</strong> table. No worries in here, it's working if I delete the entry by using simple <code>DELETE</code>. However, I need to specify some conditions:</p>
  
  <p><strong>PAGES</strong> table</p>
  
  <pre><code>+--------------------------+--------------+------+-----+---------+----------------+
  | Field                    | Type         | Null | Key | Default | Extra          |
  +--------------------------+--------------+------+-----+---------+----------------+
  | page_id                  | int(11)      | NO   | PRI | NULL    | auto_increment |
  | users_id                 | int(11)      | NO   | MUL | NULL    |                |
  | page_value               | varchar(20)  | NO   | UNI | NULL    |                |
  +--------------------------+--------------+------+-----+---------+----------------+
  </code></pre>
  
  <p><strong>OBJECTS</strong> table</p>
  
  <pre><code>+----------------------------+-------------+------+-----+---------+----------------+
  | Field                      | Type        | Null | Key | Default | Extra          |
  +----------------------------+-------------+------+-----+---------+----------------+
  | objects_id                 | int(11)     | NO   | PRI | NULL    | auto_increment |
  | page_id                    | int(11)     | NO   | MUL | NULL    |                |
  | objects_name               | varchar(50) | NO   |     | NULL    |                |
  | objects_avail              | varchar(20) | NO   |     | NULL    |                |
  +----------------------------+-------------+------+-----+---------+----------------+
  </code></pre>
  
  <p>If <code>objects_avail == "ALL"</code>, I must not include that entry in cascade delete. I came up with this SQL query but got an error:</p>
  
  <pre><code>$query = "
      DELETE FROM pages AS p 
      INNER JOIN objects AS o ON p.page_id = o.page_id 
      WHERE p.page_id = ? 
        AND p.users_id = ? 
        AND p.page_value = ? 
        AND o.objects_avail != ?";
  </code></pre>
  
  <p>The error thrown:</p>
  
  <blockquote>
    <p>["42000",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 'AS p INNER JOIN objects AS o ON p.page_id = o.page_id WHER'
    at line 1"]</p>
  </blockquote>
  
  <p>Example value for the PDO placeholders:</p>
  
  <p><code>$params = array(81,5,"main page","ALL");</code></p>
  
  <p>where all of this is valid and I'm sure this is not where the problem is.</p>
  
  <p>I doubt or prettry sure I'm missing some in my query, any suggestions please?</p>