Error trying to delete with INNER JOIN in MYSQL

Asked

Viewed 7,167 times

1

DELETE FROM `tb_users` 
INNER JOIN `tb_marker` ON tb_users.id_users` = `tb_marker.id_users` 
WHERE `tb_users.id_users` = 12

Follow below the error:

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 'INNER JOIN `tb_marker` on `tb_users.id_users` = `tb_marker.id_users` WHERE `tb_u' at line 1

  • I did not understand, if you have id_users, it would not be simpler to remove the Internet and consider only Where as a search clause?

2 answers

8

You need to specify from which table you want to delete the record.

In the example, I added an alias to the table tb_users and specified that I wanted to remove the record from this table.

DELETE u.* FROM tb_users u --Para remover apenas de tb_users
INNER JOIN tb_marker m
  on u.id_users = m.id_users
WHERE tb_users.id_users = 12

It is important you note that the Id is

  • I don’t know if my mysql is having any problems, but it does not accept anything between DELETE and FROM. Both in DELETE DO jbueno and lnkeliz.

  • @Marcospereira I was a little busy yesterday, you already found the problem?

  • would like to delete tbm records from tb_marker.

3

You need to specify which table you want to delete from, for example:

DELETE `tb_users` FROM `tb_users` 
INNER JOIN `tb_marker` 
  on `tb_users.id_users` = `tb_marker.id_users` 
WHERE `tb_users.id_users` = 12

If you want to delete from both specify both.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.