Skip to content
Advertisement

Alias an entire table’s fields

Let’s say I am querying/joining two tables, each with certain identical field names:

Is it possible to prefix the columns for each table with the tablename (or some other prefix), so for example instead of getting data such as:

It looks like:

Without doing it manually for every single field?

Advertisement

Answer

In MySQL you can do:

Followed by:

That will show you a rewritten version of the original query with quoted, fully qualified column and table names like so:

You then need to do some regex find-replace afterwards. So yes, do it manually.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement