patrick
patrick

Reputation: 16949

Is there a way in MySQL to have one column be just a reference to another column on the same table?

Is there a way in MySQL to have one column be just a reference to another column on the same table?

I am dealing with a really old MySQL database that has no naming conventions. I can't just rename the columns because that would break a lot of code. So I thought it would be cool if I could add a "shortcut column" to the poorly named column and then use them interchangeably.

Upvotes: 0

Views: 61

Answers (2)

Michael Benjamin
Michael Benjamin

Reputation: 2915

Have you considered creating a view?

CREATE VIEW view_name 
AS SELECT *, bad_name as New_name
FROM table

Upvotes: 1

George
George

Reputation: 2213

I am not exactly sure what you mean by 'reference' (an example would be nice), but... in the SQL statement, you can define the same column multiple times and specify an alias to the column name.

Something like this:

SELECT *, [this_is_a_really_bad_name] as myNewName FROM MyTable

Assuming the table MyTable has the badly designed column this_is_a_really_bad_name, you can now refer to that column by its old name or as myNewName

Is that what you are trying to achieve?

Upvotes: 1

Related Questions