Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL update query issue

Tags:

sql

sql-update

I just accidentally noticed that a Query like

Update tableA tableA set id = '5'

Works fine. Should this give error as I am using table name twice here. Any thoughts why is this working fine ?

like image 465
Andy897 Avatar asked Dec 04 '25 05:12

Andy897


2 Answers

Because the second tableA is seen as an alias. There is no constraint in regards to the name of the alias, so you can have the same name on the alias as the table name.

like image 84
Radu Gheorghiu Avatar answered Dec 05 '25 19:12

Radu Gheorghiu


your code exactly equal

Update tableA as 'tableA' set id = "5"

or

Update tableA as "tableA" set id = "5"

this is simple alias as Sql Alias Tutorial

like image 43
Ayfan Avatar answered Dec 05 '25 21:12

Ayfan