Categories
CMS Joomla Mastering Development

Deleting rows in two different tables

I’m trying to make function (task) and deleting rows in two tables. But I don’t get this sql query working, I only got this error:

1064 - An error has occurred.

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'INNER JOIN `#__codes2` WHERE #__codes' at line 2

What is the right way to doing this in Joomla?

public function delete_codes(){

  $id = $this->input->getInt('id'); 

  $db = JFactory::getDBO(); 
//$sql = "DELETE FROM `#__codes` WHERE `code_id` = $id";

  $sql = "DELETE FROM `#__codes` 
             INNER JOIN `#__codes2 
             WHERE #__codes.code_id = $id
             AND #__codes2.id = $id";

  $db->setQuery($sql); 
  $db->execute();
  
die();

}

Leave a Reply

Your email address will not be published. Required fields are marked *