SQL results returned in tablename.fieldname format
When I run a query that is selecting fields from multiple tables, i.e. for a join, I would do something like:
SELECT table1.field1, table2.field2 FROM table1 JOIN table2 ON table1.field1 = table2.field1;
When the results of a query like this is returned the array only has the field names as the index, not the combination of tablename.fieldname, and I am wondering if it is possible to get it to return the data in this format because it is re开发者_如何学Pythonquired by a plugin that I use.
Thank you.
EDIT: I thought of doing an alias, but the way that the plugin works is it takes the columns I give it literally, and then looks for those EXACT names in the array. Basically I give it the columns, it dynamically gets the data and displays it. So if I give it 'table1.field1 AS alias', it will look for that but the resulting field will be just 'alias'.
EDIT 2: I found a solution to my problem, it was not a SQL solution. I manipulated the resulting array of the query with PHP to get it back into the format that I needed to be in.
One option is to use alias for columns.
There is no way to do it automatically. You can just alias them, though -
SELECT table1.field1 as [table1.field1], table2.field2 as [table2.field2] FROM table1 JOIN table2 ON table1.field1 = table2.field1
精彩评论