I\'d like to do something like this:
SELECT table.id AS prefix_id, table.name AS prefix_name
... and have the prefix added dynamically to a
When you reference the results, you can reference each column by the tablename.column . Therefore you have a default prefix that is appended to each column name.
SELECT table.id,table.name,other.name FROM table,other Where other.name = table.name;
I can imagine a situation where this could be useful if you have multiple data models in a list that you need to populate from a single SQL query.
It should be possible to use DESCRIBE or SHOW COLUMNS on those tables before the SELECT query. That way, you know all of the field names for each table. This doesn't help with any potential field name conflicts though.
I am not going to comment on if this is a good idea or not. Each developer must decide where to draw the line between flexibility, laziness and good practice.
In mysqli you can use the php function
mysqli_fetch_fields()
for fieldinformations - so you get the tablename of each collumn
To avoid ambiguity in columns with multiple tables it appears you must manually specify each column name that exists with the same name in more than one table.
http://dev.mysql.com/doc/refman/5.0/en/identifier-qualifiers.html