I am going through all the columns of a row's table's columns (that was a tricky way of saying it - basically I have a row "R", where I use R.Table.Columns to iterate through them).
For each column, I would like to know which table it belongs to.
However, with the following query, only 1 table appears in the resultset. How come? I need to distinguish between the different tables, even if the column names are the same.
SELECT * FROM User LEFT OUTER JOIN Prov开发者_JS百科ider ON User.ProviderID=Provider.ID WHERE User.IsDeleted=false
Use aliases:
SELECT
table1.column1 AS foo,
table2.column1 AS bar,
...
Using SELECT * is bad practice anyway: SELECT * is evil
You should strongly consider using the show tables and show columns commands for database discovery
You can then generate queries from that and avoid using select *
To awnser your question more directly, i dont think its possible to get the table name for a column in a result set since those columns doent have to come from a table at all. Consider this completely valid query for example:
select 'foo' as bar, 1+1 as result;
精彩评论