[kwlug-disc] [OT] how to create a mysql table alias in the db itself?

John Van Ostrand john at netdirect.ca
Tue Mar 9 15:26:37 EST 2010

----- "Robert P. J. Day" <rpjday at crashcourse.ca> wrote:

> i have a bunch of mysql queries from two different sources, and they
> purport to work on the same database but they access the same table
> by
> two different names.  can i add a simple alias to the database for
> just that one table?
>   i know i can add an alias to the queries themselves but there are
> hundreds of them and that would be painful.  i also see something
> called "views" which might work.  but is there a canonical way to
> simply add an alternative name for an existing table within the
> database itself so that all the existing queries don't need to be
> munged?  thanks.

Seems to me views are what you need. There is the concept of aliases within an SQL statement.


SELECT * from MyTable m LEFT JOIN OtherTable o where m.id = o.id;

In this case the 'm' is the alias for the table MyTable and 'o' is the alias for OtherTable, but it's only valid within the SQL statement in which it was defined.

More information about the kwlug-disc mailing list