Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a table alias in MySQL

I am migrating an MS Access application (which has linked tables to a MSSQL Server) to MySQL.

As a means to overcome some MSAccess table naming problems, I am seeking a solution to add a MySQL table alias that will point to an existing table in the MySQL database. Ideally I would like to create the alias 'dbo_customers' in mysql that would point to the customers table also in mysql.

To be clear I am not wanting to alias a table name inside a query like this:

SELECT * FROM customers AS dbo_customers 

But rather I would like to be able issue the following query:

SELECT * FROM dbo_customers 

and have it return data from the customers table.

like image 611
rswolff Avatar asked Dec 11 '09 18:12

rswolff


People also ask

What is table alias in MySQL?

SQL aliases are used to give a table, or a column in a table, a temporary name. Aliases are often used to make column names more readable. An alias only exists for the duration of that query. An alias is created with the AS keyword.

What is alias name in MySQL write an example?

Example - ALIAS a column For example, when using the MAX function, you might alias the result of the MAX function in MySQL. For example: SELECT department, MAX(salary) AS highest FROM employees GROUP BY department; In this example, we've aliased the MAX(salary) field as highest.

How do you name a table in alias?

The basic syntax of a table alias is as follows. SELECT column1, column2.... FROM table_name AS alias_name WHERE [condition];


1 Answers

Off the top of my head

CREATE VIEW dbo_customers AS SELECT * FROM customers 

Maybe not the best solution but should work as the view is updatable. Will definitely work for Read Only

like image 117
DrewM Avatar answered Oct 14 '22 14:10

DrewM