使用“UNION”删除MySQLI查询

I want to delete some informations of my database in 2 tables.

First question, is it possible ? If yes:

I had tried a UNION DELETE query, but it doesn't work.

$delete = mysqli_query($sql, "(DELETE FROM table1 WHERE id LIKE '".$id."' && userid LIKE '".$userid."') UNION (DELETE FROM table2 WHERE source_id LIKE '".$id."' && userid LIKE '".$userid."')");

UNION is used only with SELECT statements:

http://dev.mysql.com/doc/refman/5.7/en/union.html

If you don't want to use two separate DELETE statements and those two tables are related, try using the JOIN statement:

https://dev.mysql.com/doc/refman/5.7/en/join.html

Try this :

DELETE FROM 
    n.table1 INNER JOIN m.table2
WHERE 
    n.id = m.source 
  AND 
    n.userid = m.userid 
  AND  
    n.id LIKE '".$id."' 
  AND 
    n.userid LIKE '".$userid."' 

UNION ( set operations ), JOINS all these are used to show data, i.e., used with SELECT, when multiple tables are to be used to fetch data.

to DELETE or UPDATE, please use separate queries!!

In your case

$delete = mysqli_query($sql, "(DELETE FROM table1 WHERE id LIKE '".$id."' && userid LIKE '".$userid."'));

if($delete)
{
   $delete2 = mysqli_query($sql, "(DELETE FROM table2 WHERE source_id LIKE '".$id."' && userid LIKE '".$userid."')");
}