Why do we provide alias names after "DELETE" in multiple remote

These can be very silly questions, but I really want to know if anyone has any suggestions:

Separate table Delete Correct query: delete from Vehicle_owner, where id = 3;

Single Table Remove InCorrect Query: Remove from Vehicle_owner v where v.id = 3

Mulitple Table Delete: remove v, s from vehicle v, category s, where v.id = 3 and v.id = s.id;

Qs 1: I was wondering why 1st of them is right and why 2nd is wrong. I am mainly looking for logical answers that explain why the wrong alias request in the delete request is wrong.

Qs 2: why do we keep two aliases after the DELETE keyword for multiple deletions. In any case, we provide complete information about the state of the connection. So why is it created this way.

+3


source to share


2 answers


  • The second is not true because if you use an alias the SQL statement is considered a multi-table version of the table DELETE

    that just has only one table. Thus, it must follow other multi-table rules DELETE

    . There is no place in the syntax for single-table DELETE

    to specify an alias.

  • You don't need to have aliases, but you do need to specify which of the tables you are deleting from. Therefore, you will list tables or their aliases immediately after the keyword DELETE

    . Otherwise, MySQL will not know whether to delete rows only from the first table (if there are other tables to filter), or to delete from all tables, or some combination.



See: https://dev.mysql.com/doc/refman/5.5/en/delete.html

+2


source


Completely correct syntax for your second example:

delete v from vehicle_owner as v where v.id = 3



After you have specified an alias, you also need to specify it in the delete clause.

For your second question, I'm not entirely sure what you are asking.

+1


source







All Articles