View and table in same name is it possible
As stated, you can't do it with views, but you can with temporary tables.
If you create a temporary table with the same name as an actual table, the temporary table will shadow (hide) the actual table. This means that you can't access the actual table until you have dropped the temporary table:
mysql> create table t select 1; # actual table tQuery OK, 1 row affected (0.58 sec)Records: 1 Duplicates: 0 Warnings: 0mysql> create temporary table t select*from t; # temp table tQuery OK, 1 row affected (0.53 sec)Records: 1 Duplicates: 0 Warnings: 0mysql> insert t select 2; # t refers to the temp tableQuery OK, 1 row affected (0.06 sec)Records: 1 Duplicates: 0 Warnings: 0mysql> select*from t; # temp table+---+| 1 |+---+| 1 || 2 |+---+2 rows in set (0.00 sec)mysql> drop table t; # temp tableQuery OK, 0 rows affected (0.06 sec)mysql> show tables like "t"; # verify that actual table still exists. show tables will not show temporary tables+--------------------+| Tables_in_test (t) |+--------------------+| t |+--------------------+1 row in set (0.00 sec)mysql>mysql> select*from t; # now t refers to the actual table+---+| 1 |+---+| 1 |+---+1 row in set (0.00 sec)mysql> drop table t; # actual tableQuery OK, 0 rows affected (0.14 sec)mysql>
However, temporary tables are gone (even if you do not drop
them) once your session is disconnected. You'll need to re-create them every time you connect.